Life is short. You need Python.
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 9) #0부터 10사이를 9등분으로 쪼갠 리스트 생성
y = np.random.randn(9) #평균값이 0, 표준편차가 1인 가우시안 표준정규분포를 따르는 1*9 크기의 난수를 발생함
plt.scatter(x, y)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 9) #0부터 10사이를 9등분으로 쪼갠 리스트 생성
y = np.random.randn(9) #평균값이 0, 표준편차가 1인 가우시안 표준정규분포를 따르는 1*9 크기의 난수를 발생함
plt.scatter(x, y)
<matplotlib.collections.PathCollection at 0x22bf5a72160>
from matplotlib.pylab import *
x = linspace(0, 10, 9)
y = randn(9)
scatter(x, y)
show()
plt.title("Plot")
plt.plot([1, 4, 9, 16])
plt.show()
plt.title("location of x_tick")
plt.plot([10, 20, 30, 40], [1, 4, 9, 16])
plt.show()
plt.title("'rs--' style plot ")
plt.plot([10, 20, 30, 40], [1, 4, 9, 16], 'rs--')
plt.show()
#플롯 수정하기: 선 색상과 스타일
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x - 0), color='blue') # 색상을 이름으로 지정
plt.plot(x, np.sin(x - 1), color='g') # 짧은 색상 코드(rgbcmyk)
plt.plot(x, np.sin(x - 2), color='0.75') # 0과 1 사이로 회색조 지정
plt.plot(x, np.sin(x - 4), color=(1.0, 0.2, 0.3)) # RGB 튜플, 0과 1 값
plt.show()
plt.plot([10, 20, 30, 40], [1, 4, 9, 16], c="b",
lw=5, ls="--", marker="o", ms=15, mec="g", mew=5, mfc="r")
plt.title("Example of applying styles")
plt.show()
plt.title("the range of the x-axis and y-axis")
plt.plot([10, 20, 30, 40], [1, 4, 9, 16],
c="b", lw=5, ls="--", marker="o", ms=15, mec="g", mew=5, mfc="r")
plt.xlim(0, 50)
plt.ylim(-10, 30)
plt.show()
X = np.linspace(-np.pi, np.pi, 256)
C = np.cos(X)
plt.title("Tick label setting for x-axis and y-axis")
plt.plot(X, C)
plt.xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi])
plt.yticks([-1, 0, +1])
plt.show()
X = np.linspace(-np.pi, np.pi, 256)
C = np.cos(X)
plt.title("Tap label setting for x-axis and y-axis")
plt.plot(X, C)
plt.xticks([-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi])
plt.yticks([-1, 0, +1])
plt.grid(True)
plt.show()
t = np.arange(0., 5., 0.2)
plt.title("Draw multiple lines in line plot")
plt.plot(t, t, 'r--', t, 0.5 * t**2, 'bs:', t, 0.2 * t**3, 'g^-')
plt.grid(True)
plt.show()
X = np.linspace(-np.pi, np.pi, 256)
C, S = np.cos(X), np.sin(X)
plt.title("Plot with Legend")
plt.plot(X, C, ls="--", label="cosine")
plt.plot(X, S, ls=":", label="sine")
plt.legend(loc=2)
plt.grid(True)
plt.show()
X = np.linspace(-np.pi, np.pi, 256)
C, S = np.cos(X), np.sin(X)
plt.plot(X, C, label="cosine")
plt.xlabel("time")
plt.ylabel("amplitude")
plt.title("Cosine Plot")
plt.grid(True)
plt.show()
plt.title("Represents multiple plot commands in one plot")
plt.plot([1, 4, 9, 16],
c="b", lw=5, ls="--", marker="o", ms=15, mec="g", mew=5, mfc="r")
# plt.hold(True) # <- 1,5 버전에서는 이 코드가 필요하다.
plt.plot([9, 16, 4, 1],
c="k", lw=3, ls=":", marker="s", ms=10, mec="m", mew=5, mfc="c")
# plt.hold(False) # <- 1,5 버전에서는 이 코드가 필요하다.
plt.show()
#매트랩 스타일의 인터페이스
# 두개의 패널 중 첫번째 패널을 생성하고 현재 축(axis)을 설정
plt.subplot(2, 1, 1) # (rows, columns, panel number)
plt.plot(x, np.sin(x))
plt.subplot(2, 1, 2)
plt.plot(x, np.cos(x))
plt.show()
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')
data = np.random.randn(1000)
plt.hist(data)
(array([ 11., 39., 93., 174., 253., 221., 137., 51., 16., 5.]),
array([-2.88234171, -2.2631336 , -1.64392549, -1.02471738, -0.40550927,
0.21369884, 0.83290695, 1.45211506, 2.07132317, 2.69053128,
3.30973939]),
<a list of 10 Patch objects>)
plt.hist(data);
plt.hist(data, bins=30, density=True);
# Seaborn과 Matplotlib의 차이
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
rng = np.random.RandomState(0)
x = np.linspace(0, 10, 500)
y = np.cumsum(rng.randn(500, 6), 0)
plt.plot(x, y)
plt.legend('ABCDEF', ncol=2, loc='upper left')
plt.show()
import seaborn as sns
sns.set()
plt.plot(x, y)
plt.legend('ABCDEF', ncol=2, loc='upper left')
plt.show()
iris = sns.load_dataset("iris") #붓꽃 데이터
titanic = sns.load_dataset("titanic") #타이타닉호 데이터
tips = sns.load_dataset("tips") #팁 데이터
flights = sns.load_dataset("flights") #여객운송 데이터
x = iris.petal_length.values
x
array([1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1.6, 1.4,
1.1, 1.2, 1.5, 1.3, 1.4, 1.7, 1.5, 1.7, 1.5, 1. , 1.7, 1.9, 1.6,
1.6, 1.5, 1.4, 1.6, 1.6, 1.5, 1.5, 1.4, 1.5, 1.2, 1.3, 1.4, 1.3,
1.5, 1.3, 1.3, 1.3, 1.6, 1.9, 1.4, 1.6, 1.4, 1.5, 1.4, 4.7, 4.5,
4.9, 4. , 4.6, 4.5, 4.7, 3.3, 4.6, 3.9, 3.5, 4.2, 4. , 4.7, 3.6,
4.4, 4.5, 4.1, 4.5, 3.9, 4.8, 4. , 4.9, 4.7, 4.3, 4.4, 4.8, 5. ,
4.5, 3.5, 3.8, 3.7, 3.9, 5.1, 4.5, 4.5, 4.7, 4.4, 4.1, 4. , 4.4,
4.6, 4. , 3.3, 4.2, 4.2, 4.2, 4.3, 3. , 4.1, 6. , 5.1, 5.9, 5.6,
5.8, 6.6, 4.5, 6.3, 5.8, 6.1, 5.1, 5.3, 5.5, 5. , 5.1, 5.3, 5.5,
6.7, 6.9, 5. , 5.7, 4.9, 6.7, 4.9, 5.7, 6. , 4.8, 4.9, 5.6, 5.8,
6.1, 6.4, 5.6, 5.1, 5.6, 6.1, 5.6, 5.5, 4.8, 5.4, 5.6, 5.1, 5.1,
5.9, 5.7, 5.2, 5. , 5.2, 5.4, 5.1])
sns.rugplot(x)
plt.title("'Rug Plot' about petal length in Iris Data")
plt.show()
sns.kdeplot(x)
plt.title("'Kernal Density Plot' about petal length in Iris Data")
plt.show()
sns.distplot(x, kde=True, rug=True)
plt.title("'Dist Plot' about petal length in Iris Data")
plt.show()
countplot(x=”class_name”, data=dataframe)
sns.countplot(x="class", data=titanic)
plt.title("Number of passengers per class of Titanic")
plt.show()
sns.countplot(x="day", data=tips)
plt.title("Number of times a day's tip was given")
plt.show()