# 使用matplotlib绘制简单图表

1，使用plot()绘制折线图：

``````# _maximum_minimum_temperatures
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4,19)
y_max = np.array([32,33,34,34,33,31,30,29,30,29,26,23,21,25,31])
y_min = np.array([19,19,20,22,22,21,16,18,18,17,14,15,16,16,16])
plt.plot(x,y_max)
plt.plot(x,y_min)
plt.title("41")
plt.show()
``````

2，使用bar()绘制柱形图或堆积柱形图：

``````import matplotlib.pyplot as plt
import numpy as np
x = np.arange(5)
y1 = np.array([10,8,7,11,13])
bar_width = 0.3
plt.bar(x,y1,tick_label=['a','b','c','d','e'], width=bar_width)
plt.title("41")
plt.show()
``````

``````x = np.arange(5)
y1 = np.array([10,8,7,11,13])
y2 = np.array([9,6,5,10,12])
bar_width = 0.3
plt.bar(x,y1,tick_label=['a','b','c','d','e'], width=bar_width)
plt.bar(x,y2,bottom=y1, width=bar_width)
plt.title("41")
plt.show()
``````

3，使用barh()绘制条形图或堆积条形图：

``````import matplotlib.pyplot as plt
import numpy as np
y = np.arange(5)
x1 = np.array([10,8,7,11,13])
bar_height=0.3
plt.barh(y,x1,tick_label=['a','b','c','d','e'], height=bar_height)
plt.title("41")
plt.show()
``````

``````y = np.arange(5)
x1 = np.array([10,8,7,11,13])
x2 = np.array([9,7,6,10,12])
bar_height=0.3
plt.barh(y,x1,tick_label=['a','b','c','d','e'], height=bar_height)
plt.barh(y+bar_height,x2,height=bar_height)
plt.title("41")
plt.show()
``````

4，使用stackplot绘制堆积面积图：

``````import numpy as np
import matplotlib.pyplot as plt
x=np.arange(6)
y1= np.array([1,4,3,5,6,7])
y2=np.array([1,3,4,2,7,6])
y3=np.array([3,4,3,6,5,5])
plt.stackplot(x,y1,y2,y3)
plt.title("41")
plt.show()
``````

5，使用hist()绘制直方图：

``````scores=np.random.randint(0,100,50)
plt.hist(scores,bins=8,histtype='stepfilled')
plt.title('41')
plt.show()
``````

6，使用pie()绘制饼图或圆环图：

``````data =np.array([20,50,10,15,30,55])
pie_labels=np.array(['A','B','C','D','E','F'])
plt.title('41')
plt.show()
``````

``````data =np.array([20,50,10,15,30,55])
pie_labels=np.array(['A','B','C','D','E','F'])
plt.title('41')
plt.show()
``````

7，使用scatter()绘制散点图或气泡图：

``````num=50
x=np.random.rand(num)
y=np.random.rand(num)
plt.title('41')
plt.scatter(x,y)
``````

``````num=50
x=np.random.rand(num)
y=np.random.rand(num)
area=(30*np.random.rand(num))**2
plt.title('41')
plt.scatter(x,y,s=area)
``````

8，使用boxplot()绘制箱型图：

``````data =np.random.randn(100)
plt.boxplot(data,meanline=True,widths=0.3,patch_artist=True,showfliers=False)
plt.title('41')
plt.show()
``````

9，使用polar()绘制 雷达图：

``````plt.rcParams['font.family']= 'SimHei'
plt.rcParams['axes.unicode_minus']=False
dim_num=6
data=np.array([[0.40,0.32,0.35,0.30,0.30,0.88],
[0.85,0.35,0.30,0.40,0.40,0.30],
[0.43,0.89,0.30,0.28,0.22,0.30],
[0.30,0.25,0.48,0.85,0.45,0.40],
[0.20,0.38,0.87,0.45,0.32,0.28],
[0.34,0.31,0.38,0.40,0.92,0.28]])
angles=np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
angles=np.concatenate((angles,[angles[0]]))
data=np.concatenate((data,[data[0]]))