from matplotlib.pyplot import *
import matplotlib.pyplot as plt
def learn_1():
#plot儲存數據集,多組數據展現多條線
”’
plot([1,2,3,2,3,2,2,1])
plot([4,3,2,1],[1,2,3,4])
”’
x=[1,2,3,4]
y=[5,4,3,2]
figure()
subplot(231)
plot(x,y)
subplot(232)
bar(x,y)
subplot(233)
barh(x,y)
subplot(234)
bar(x,y)
y1=[7,8,5,3]
bar(x,y1,bottom=y,color='r')
subplot(235)
boxplot(x)
subplot(236)
scatter(x,y)
plt.show()
if name == ‘main‘:
learn_1()
此代碼分4部分:
1、導入合適的包
2、建立數據源
3、劃分子圖板塊
4、函數調用顯示