matplotlib¶
matplotlib.pyplot 라이브러리 import
In [1]:
import matplotlib.pyplot as plt
In [2]:
plt.plot([1,2,10], [10,20,5])#x,y 값 (1,10) (2,20) (10, 5)
plt.show()
In [3]:
plt.plot(['a', 'b', 'c'], [10, 29 ,5])
plt.show
Out[3]:
<function matplotlib.pyplot.show(close=None, block=None)>
axis()¶
- 축의 범위 지정
In [4]:
plt.axis([-0.5, 2.2, 0, 21]) #[xmin, xmax, ymin, ymax]
plt.plot(['z', 'b', 'a'],[3,10,11])
plt.show()
In [6]:
def make_chart_simple_line_chart():
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.3, 2862.5, 5979.6, 10289.7, 14958.3]
plt.plot(years, gdp,marker='o', color = 'blue', linestyle = 'solid', label = 'label')
#add title
plt.title("Nominal GDP")
#add label to the y-axis
plt.ylabel("Billions of $")
plt.xlabel("years")
#범례표시
plt.legend()
plt.show()
make_chart_simple_line_chart()
여러개의 plot 그래프 그리기¶
In [7]:
plt.plot([1,2,3,4,5], [10,20,30,40,50])
plt.plot([2,3,4,5,6], [30,30,20,10,90])
Out[7]:
[<matplotlib.lines.Line2D at 0x1891135f6a0>]
In [8]:
import numpy as np
t = np.arange(0., 5., 0.2)
#빨간 대쉬, 파란 사각형, 녹색 삼각형
plt.plot(t,t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
In [9]:
plt.plot([1,2,3,4,5], [10,20,30,40,50])
plt.plot([2,3,4,5,6], [30,30,20,10,90])
plt.xticks([0,1,2,3,4], labels=['one', 'two', 'three', 'four', 'five'])
plt.show()
'Data_Python > Matplotlib' 카테고리의 다른 글
[Matplotlib] pie 그래프와 예제 plt.pie() (0) | 2022.04.14 |
---|---|
[Matplotlib] Scatter 그래프와 예제 plt.scatter (0) | 2022.04.14 |
[Matplotlib] Bar 그래프와 예제 plt.bar() (0) | 2022.04.14 |