【转】Python应用matplotlib.pyplot画图总结

部分一:

import numpy as np
import matplotlib.pyplot as plt

a = plt.subplot(1,1,1)
x = np.arange(0.,3.,0.1)

#这里b表示blue,g表示green,r表示red,-表示连接线,--表示虚线链接
a1 = a.plot(x, x, 'bx-', label = 'line 1')
a2 = a.plot(x, x**2, 'g^-', label = 'line2')
a3 = a.plot(x, x**3, 'gv-', label = 'line3')
a4 = a.plot(x, 3*x, 'ro-', label = 'line4')
a4 = a.plot(x, 2*x, 'r*-', label = 'line5')
a4 = a.plot(x, 2*x+1, 'ro--', label = 'line6')

#标记图的题目,x和y轴
plt.title("My matplotlib learning")
plt.xlabel("X")
plt.ylabel("Y")


#显示图例
handles, labels = a.get_legend_handles_labels()
a.legend(handles[::-1], labels[::-1])
plt.show()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容