matplotlib官网
在一张图中画多跳线
https://jingyan.baidu.com/article/b7001fe1db54320e7282ddfe.html
import numpy as np
import matplotlib.pyplot as plt
# 以0.2为间隔均匀采样
t = np.arange(0., 5., 0.2)
#查看t的值
print t
# 'r--':红色的需要;'bs':蓝色方块;'g^':绿色三角
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
matplotlib介绍
https://zhuanlan.zhihu.com/p/109245779
Python设置matplotlib.plot的坐标轴刻度间隔以及刻度范围
https://www.jb51.net/article/163842.htm
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
#从pyplot导入MultipleLocator类,这个类用于设置刻度间隔
x_values=list(range(11))
y_values=[x**2 for x in x_values]
plt.plot(x_values,y_values,c='green')
plt.title('Squares',fontsize=24)
plt.tick_params(axis='both',which='major',labelsize=14)
plt.xlabel('Numbers',fontsize=14)
plt.ylabel('Squares',fontsize=14)
x_major_locator=MultipleLocator(1)
#把x轴的刻度间隔设置为1,并存在变量里
y_major_locator=MultipleLocator(10)
#把y轴的刻度间隔设置为10,并存在变量里
ax=plt.gca()
#ax为两条坐标轴的实例
ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为1的倍数
ax.yaxis.set_major_locator(y_major_locator)
#把y轴的主刻度设置为10的倍数
plt.xlim(-0.5,11)
#把x轴的刻度范围设置为-0.5到11,因为0.5不满一个刻度间隔,所以数字不会显示出来,但是能看到一点空白
plt.ylim(-5,110)
#把y轴的刻度范围设置为-5到110,同理,-5不会标出来,但是能看到一点空白
plt.show()
图例
中文显示
只需加上一句
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
matplotlib图例中文乱码?
https://www.zhihu.com/question/25404709/answer/309784195
图例显示方法(多种
https://www.cnblogs.com/linblogs/p/9642031.html
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']
tickSea=dataSea2001[indSea,0]
#plt.plot(CISea[15:-2,0],'b',ECSea[15:-2,0],'r')
#plt.xlabel('时间')
#plt.ylabel('累计值')
x_major_locator=plt.MultipleLocator(9)
#把x轴的刻度间隔设置为3,并存在变量里
ax=plt.gca()
#ax为两条坐标轴的实例
ax.xaxis.set_major_locator(x_major_locator)
#把x轴的主刻度设置为9的倍数
#plt.plot(tickSea[15:-2],CISea[15:-2,0],'b')
#plt.plot(tickSea[15:-2],CISea[15:-2,1],'b',tickSea[15:-2],ECSea[15:-2,2],'r')
plt.plot(tickSea[15:-2],CISea[15:-2,1],'b',label='sr')
plt.plot(tickSea[15:-2],ECSea[15:-2,2],'r',label='GDP')
plt.legend(['社会融资规模:累计值','GDP:现价:累计值'])
#plt.show()
绘制多个图形
subplot
https://zhuanlan.zhihu.com/p/109245779
数据可视化——次坐标
https://blog.csdn.net/fly_wt/article/details/84665696
fig,ax0=plt.subplots()
ax0i=ax0.twinx()
ax0.plot(tickV,CLvalue[:,1],'b')
ax0i.plot(tickV,ECvalue[:,0],'r')