https://blog.csdn.net/weixin_39778570/article/details/81157884
官方参考文档:
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot
tutorials
https://matplotlib.org/tutorials/introductory/sample_plots.html#sphx-glr-tutorials-introductory-sample-plots-py
import pandas as pd
import numpy as np
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
a = [1,2,3]
# 传入a为x轴,y轴默认
plt.plot(a)
[0x1258dde4128>]
# 显示
plt.show()
a = [1,2,3]
b = [4,5,6]
# 传入x,y轴
plt.plot(a,b)
[0x1258e0d5ba8>]
plt.show()
# jupyter 中导入这一行可以直接显示图片
%matplotlib inline
plt.plot(a,b)
[0x1258e39dd68>]
# 计算运行时间
%timeit np.arange(10)
570 ns ± 6.99 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
# 修改画出来的图表的样子,*号图
plt.plot(a,b,'*')
[0x1258e419438>]
# 红色的虚线
plt.plot(a,b,'r--')
[0x1258f66d390>]
# 蓝色的虚线
plt.plot(a,b,'b--')
[0x1258f6ceef0>]
# c传入两个图表
c = [10,8,6]
d = [1,8,3]
plt.plot(a,b,c,d)
# 修改线的形状
plt.plot(a,b,'b--',c,d,'r*')
[0x1258f865a20>,
0x1258f865be0>]
# 画一个正弦函数
t = np.arange(0.0, 2., 0.1)
t.size
Out[]:20
s = np.sin(t*np.pi)
plt.plot(t,s,'r--')
[0x1258f937b38>]
# 画两条线,并设置x,y轴的label和title
plt.plot(t,s,'r--', t*2, s, '--')
plt.xlabel('this is x')
plt.ylabel('this is y')
plt.title('this is a demo')
# 需要有图例的名字才能显示
plt.legend()
# 设置每个图的label
plt.plot(t,s,'r--', label='aaaa')
plt.plot(t*2, s, '--',label='bbbb')
plt.xlabel('this is x')
plt.ylabel('this is y')
plt.title('this is a demo')
plt.legend()