height = [np.random.randn()*i for i in range(1,6)]
height
names = ['A','B','C','D','E']
y_pos = np.arange(len(names))
y_pos
plt.bar(y_pos, height)
plt.xticks(y_pos, names, fontweight='bold')
plt.xlabel('group')
# stacked bar plot 1
bars1 = [12, 28, 1, 8, 22]
bars2 = [28, 7, 16, 4, 10]
bars3 = [25, 3, 23, 25, 17]
r=[0,1,2,3,4]
names = ['A','B','C','D','E']
plt.bar(r, bars1, color='royalblue', edgecolor='white')
plt.bar(r, bars2, color='skyblue', edgecolor='white')
plt.bar(r, bars3, color='lightblue', edgecolor='white')
plt.xlabel('group', fontweight='bold')
plt.xticks(r, names, fontweight='bold');
# stacked bar plot 2
bar_width = 0.25
bars1 = [14, 17, 9, 8, 7]
bars2 = [14, 6, 16, 4, 10]
bars3 = [21, 3, 24, 13, 17]
r1 = np.arange(len(bars1))
r2 = [x + bar_width for x in r1]
r3 = [x + bar_width for x in r2]
print(r1, r2, r3)
plt.bar(r1, bars1, color='royalblue', width=bar_width, edgecolor='white', label='r1')
plt.bar(r2, bars2, color='skyblue', width=bar_width, edgecolor='white', label='r2')
plt.bar(r3, bars3, color='lightblue', width=bar_width, edgecolor='white', label='r3')
plt.xlabel('group', fontweight='bold')
plt.xticks([r + bar_width for r in range(len(bars1))], ['A','B','C','D','E'])
plt.legend();
#박스플롯
r1 = np.random.normal(loc=0, scale=0.5, size=100)
r2 = np.random.normal(loc=0.5, scale=1, size=100)
r3 = np.random.normal(loc=1, scale=1.5, size=100)
r4 = np.random.normal(loc=1.5, scale=2, size=100)
r5 = np.random.normal(loc=2, scale=2.5, size=100)
f, ax = plt.subplots(1, 1)
ax.boxplot((r1, r2, r3, r4, r5))
ax.set_xticklabels(['r1','r2','r3','r4','r5']);
#산전도
# 마커 종류
plt.figure(figsize=(8,4))
markers=['.',',','o','v','^','<','>','1','2','3','4','s','p','*','h','H','+','D','d','|','_']
for m in markers:
plt.plot(np.random.rand(5), np.random.rand(5), m, label="'{}'".format(m))
plt.legend(loc="center right", ncol=2)
plt.xlim(0, 1.5);
x = np.linspace(0, 10, 100)
y = np.sin(x)
# 산점도 그리기
plt.scatter(x,y,marker='o')
for i in range(9):
x = np.arange(1000)
y = np.random.randn(1000).cumsum()
plt.scatter(x, y, alpha=0.2, cmap='viridis')
# 버블 차트
x = np.random.randn(100)
y = np.random.randn(100)
colors = np.random.rand(100)
sizes = 1000 * np.random.rand(100)
plt.scatter(x, y, c=colors, s=sizes, alpha=0.3, cmap='viridis')
plt.colorbar();
# cmap 종류 : https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
x = np.random.randn(200)
y1 = np.random.randn(len(x)) # no correlation
y2 = 1.1*np.exp(x) # correlation
ax1 = plt.plot()
plt.scatter(x, y1, color='indigo', alpha=0.3, label='no correalation')
plt.scatter(x, y2, color='blue', alpha=0.3, label='correalation')
plt.grid(True)
plt.legend();
#오차 막대
x = np.linspace(0, 20, 40)
dy = 1
y = np.sin(x) + dy*np.random.randn(40)
# format='H'
plt.errorbar(x, y, yerr=dy, fmt='H');
# format='H'
plt.errorbar(x, y, yerr=dy, fmt='s', color='darkblue',
ecolor='gray', elinewidth=2, capsize=0);
#히스토그램, 구간 밀도(histogram, binnings and density)m
# 히스토그램 : 값에 대한 구간화
# bins : 구간
data = np.random.randn(10000)
plt.hist(data);
plt.hist(data, bins=50, alpha=0.5,
histtype='stepfilled', color='steelblue',
edgecolor='none');
x1 = np.random.normal(0, 1, 10000)
x2 = np.random.normal(-5, 3, 10000)
x3 = np.random.normal(5, 2, 10000)
plt.hist(x1, histtype = 'stepfilled', alpha=0.3, bins=50)
plt.hist(x2, histtype = 'stepfilled', alpha=0.3, bins=50)
plt.hist(x3, histtype = 'stepfilled', alpha=0.3, bins=50);
x = np.random.normal(size=50000)
y = x - np.random.normal(size=50000)
# 2차원 히스토그램
plt.hist2d(x, y, bins=50, cmap='OrRd')
plt.colorbar();
'Crawling > 데이터 시각화' 카테고리의 다른 글
Matplotlib_라인 플롯(Line Plot) (0) | 2022.01.10 |
---|---|
Matplotlib_라인 플롯(Line Plot) (0) | 2022.01.10 |
데이터시각화_10가지_Geo chart (0) | 2022.01.06 |
데이터시각화_10가지_Box plot (0) | 2022.01.06 |
데이터시각화_10가지_Histogram (0) | 2022.01.06 |