データ分析と可視化
21260 ワード
15.散点図
15-1. cmap
Matplotlib-cmapリンク
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' #windows
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
import pandas as pd
df = pd.read_excel('../Pandas/score3.xlsx')
df

df['학년'] = [3,3,2,1,1,3,2,2]
df

plt.scatter(df['영어'], df['수학'])
plt.xlabel('영어 점수')
plt.ylabel('수학 점수')
plt.grid()

import numpy as np
sizes = np.random.rand(8)*1000
sizes
>>> array([637.86192808, 974.03690491, 655.13163377, 305.66426581,
516.32368156, 779.08324191, 965.29779868, 382.36378487])
plt.scatter(df['영어'], df['수학'],s=sizes)
plt.xlabel('영어 점수')
plt.ylabel('수학 점수')

sizes = df['학년']*500 #1학년=500, 2학년=1000, 3학년=1500
plt.scatter(df['영어'], df['수학'],s=sizes)
plt.xlabel('영어 점수')
plt.ylabel('수학 점수')

15-1. cmap
Matplotlib-cmapリンク
plt.scatter(df['영어'], df['수학'],s=sizes, c=df['학년'], cmap='viridis', alpha=0.5)
plt.xlabel('영어 점수')
plt.ylabel('수학 점수')

plt.figure(figsize = (7,10))
plt.scatter(df['영어'], df['수학'],s=sizes, c=df['학년'], cmap='viridis', alpha=0.5)
plt.xlabel('영어 점수')
plt.ylabel('수학 점수')
plt.colorbar(ticks=[1,2,3], label='학년', shrink=0.5, orientation = 'horizontal')

16.複数のグラフィックimport matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'Malgun Gothic' #windows
matplotlib.rcParams['font.size'] = 15
matplotlib.rcParams['axes.unicode_minus'] = False
import pandas as pd
df = pd.read_excel('../Pandas/score3.xlsx')
df

# 두개의 형태를 튜플형태로 받아오는것
fig, axs = plt.subplots(2, 2, figsize = (15, 10)) # 2 x 2에 해당하는 plot들을 생성
fig.suptitle('여러 그래프 그리기')
#첫번째 그래프
axs[0, 0].bar(df['이름'], df['국어'], label = '국어점수')
axs[0, 0].set_title('첫번재 그래프')
axs[0, 0].legend()
axs[0, 0].set(xlabel = '이름', ylabel = '점수') # x, y축 label
axs[0, 0].set_facecolor('lightyellow') #전면 색
axs[0, 0].grid(ls='--', lw=0.5)
#두번째 그래프
axs[0, 1].plot(df['이름'], df['수학'], label='수학')
axs[0, 1].plot(df['이름'], df['영어'], label='영어')
axs[0, 1].legend()
#세번째 그래프
axs[1, 0].barh(df['이름'], df['키'])
#네번째 그래프
axs[1, 1].plot(df['이름'], df['사회'], color='green', alpha = 0.5)

Reference
この問題について(データ分析と可視化), 我々は、より多くの情報をここで見つけました https://velog.io/@ssjy89/나도코딩-데이터-분석-및-시각화-Matplotlib7テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol