Posts [프로그래머스 인공지능스쿨] Week3-1 Python - Matplotlib
Post
Cancel

[프로그래머스 인공지능스쿨] Week3-1 Python - Matplotlib

강의


Matplotlib

1
2
3
import matplotlib.pyplot as plt

%matplotlib inline
꺾은선 그래프(plot)
1
2
3
4
5
6
7
8
9
10
11
12
x = np.arange(-10,10,0.01)
plt.xlabel("x value")
plt.ylabel("f(x) value")
plt.axis([-5,5,0,25]) # [x_min, x_max, y_min, y_max]
plt.xticks([i for i in range(-5,6,1)])
plt.yticks([i for i in range(0,27,3)])
plt.title("y = x^2")

plt.plot(x, x**2, label='trend')

plt.legend() # 반드시 선을 그린후에 와야함
plt.show()
산점도(Scatter plot)
1
2
3
4
x = np.arange(20)
y = np.random.randint(0,20,20)
plt.scatter(x,y)
plt.show()
박스그림(Box plot)

수치형 데이터에 대한 정보 (Q1, Q2, Q3, min, max)

1
2
3
plt.title("Box plot of x, y")
plt.boxplot((x,y))
plt.show()
막대그래프(Bar plot)
1
2
3
plt.xticks(np.arange(0,20,1))
plt.bar(x,y)
plt.show()
히스토그램(histogram)
1
2
3
plt.hist(y, bins=np.arange(0,20,2))
plt.xticks(np.arange(0,20,2))
plt.show()
원형그래프(pie chart)
1
2
3
z = [100,300,200,400]
plt.pie(z, labels=['one','two','three','four'])
plt.show()

Seaborn

1
import seaborn as sns
커널밀도그림
1
2
3
4
5
6
x = np.arange(0,22,2)
y = np.random.randint(0,20,20)

sns.kdeplot(y)
# sns.kdeplot(y, shade=True) # shade 인자 넣으면 음영효과
plt.show()
카운트그림
1
2
3
4
5
vote_df = pd.DataFrame({'name':['andy','bob','cat'], 'vote':[True,True,False]})
vote_count = vote_df.groupby('vote').count()

sns.countplot(x = vote_df['vote'])
plt.show()
캣그림
1
2
3
4
5
covid = pd.read_csv("./country_wise_latest.csv")
s = sns.catplot(x='WHO Region',y='Confirmed', data=covid, kind = 'violin')
#kind 인자(default = strip)
s.fig.set_size_inches(10,6)
plt.show()
스트립그림
1
2
3
4
5
6
sns.stripplot(x='WHO Region',y='Recovered',data=covid)
plt.show()

#뭉친점들을 확인할 때 swarmplot을 사용함
sns.swarmplot(x='WHO Region',y='Recovered',data=covid)
plt.show()
히트맵
1
2
sns.heatmap(covid.corr())
plt.show()

Assignment


This post is licensed under CC BY 4.0 by the author.