어떤 데이터의 특성이 있는가를 볼 때 사용, 만약 어떤 지역의 종교단체와 경제와 상관이 있는지 Scatter로 찍어보고 있다면 다른 그래프를 이용해 유추함
Scatter는 각각의 데이터가 독립적일 때 사용한다.
import numpy as np
import matplotlib.pyplot as plt
data1=[5, 9, 11, -3, 7, -3, 13, 2, 8]
data2=[9, 11, 3, 6, -3, 13, 5, 8, 9]
plt.figure()
plt.scatter(data1, data2, s=53, c="red", alpha=0.5, label='Inline label' )
plt.scatter([1,2,3], [3,5,9], s=53, c="blue", alpha=0.5, label='Inline label' )
plt.xlim([-10,30])
plt.ylim([-10,30])
#plt.autoscale(enable=True, axis='y')
plt.legend()
plt.show()
데이터와 같이 size와 color도 배열로 넘겨줄 수 있다.
import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2 # 0 to 15 point radii
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
import numpy as np
np.random.seed(19680801)
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
for color in ['tab:blue', 'tab:orange', 'tab:green']:
n = 150
x, y = np.random.rand(2, n)
scale = 200.0 * np.random.rand(n)
ax.scatter(x, y, c=color, s=scale, label=color,
alpha=0.3, edgecolors='none')
ax.legend()
ax.grid(True)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
X = np.arange(20)
Y = np.random.randint(0, 20, 20)
S = np.abs(np.random.randn(20))*100
C = np.random.randint(0, 20, 20)
scatter = plt.scatter(X, Y, s=S, c=C, label='A')
plt.xlim(X[0]-1, X[-1]+1)
plt.ylim(np.min(Y-1), np.max(Y+1))
plt.title('scatter', pad=10)
plt.xlabel('X axis', labelpad=10)
plt.ylabel('Y axis', labelpad=10)
plt.xticks(np.linspace(X[0], X[-1], 11))
plt.yticks(np.linspace(np.min(np.append(Y, Y)), np.max(np.append(Y, Y)), 11))
plt.minorticks_on()
plt.tick_params(axis='both', which='both', direction='in', pad=8, top=True, right=True)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
# Compute areas and colors
N = 150
r = 2 * np.random.rand(N)
theta = 2 * np.pi * np.random.rand(N)
area = 200 * r**2
colors = theta
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
plt.show()