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