python之路:matplotlib之子圖(1)


備注:只是參考 實際過程中,需要用數據去填充 -18課

plt.xticks(rotation=45)X軸圖標以45°畫圖
plt.xlable() x軸是什么
plt.ylable()y軸是什么
plt.title()圖的題目


子圖的繪制:
import pandas as pd
import numpy as np
import tushare as ts
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure()
ax1 = fig.add_subplot(2,2,1) 2*2的圖形,位置在1,2,4的位置
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,4)


fig = plt.figure(figsize=(6,6)) figsize=(6,6)指定圖片的大小
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
ax1.plot(np.random.randint(1,5,5),np.arange(5))
ax2.plot(np.arange(10)*3,np.arange(10))
plt.show()

若是在一個途中畫兩條線:
plt.plot(x,y,c=’red’) 紅色的
plt.plot(z,u,c=’blue’)

fig=plt.figure(figsize(10,6))
colors=[‘red’,’blue’,’gree’,’orange’,’black’]
for I in range(5):
start_index = I *12
end_index =(I +1 )*12
subset =unrate[start_index:end_index] #取值
lable = str(1948+I)
plt.plot(subset[‘MONTH’],subset[‘VALUE’],c =colors[i],lable=lable)
plt.legend(loc=’best’)
plt.show()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM