import matplotlib.pyplot as plt
import numpy as np
# 绘制普通图像
x = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
y1 = [12,34,56,34,56,78,67,89,76,45]
y2 = [98,65,78,34,89,55,35,76,89,34]
plt.figure()
# 在绘制时设置lable, 逗号是必须的
l1, = plt.plot(x, y1, label = 'line')
l2, = plt.plot(x, y2, label = 'parabola', color = 'red', linewidth = 1.0, linestyle = '--')
# 设置坐标轴的取值范围
plt.xlim((-1, 1))
plt.ylim((0, 2))
# 设置坐标轴的lable
plt.xlabel('X axis')
plt.ylabel('Y axis')
# 设置x坐标轴刻度,
plt.xticks(np.linspace(0.1,1, 10))
# 设置y坐标轴刻度及标签,
plt.yticks(np.linspace(0,100, 11))
# 设置legend
plt.legend(handles = [l1, l2,], labels = ['hold-obj', 'surf-instr'], loc = 'best')
plt.savefig("demo.png") #保存图时,一定要放在plt.show()前面,否则一片空白
plt.show()
有可能会出现下面的问题
AttributeError: 'module' object has no attribute
解决办法:
import matplotlib.pyplot as plt
参考文章:https://blog.csdn.net/Quincuntial/article/details/70947363
参考文章:https://blog.csdn.net/helunqu2017/article/details/78641290
参考文章:https://blog.csdn.net/m0_37362454/article/details/81511427
参考文章:https://www.cnblogs.com/laoniubile/p/5893286.html
参考文章:https://www.jianshu.com/p/de223a79217a
colors = [‘k’, ‘r’, ‘yellow’, ‘b’, ‘c’, ‘m’, ‘b’, ‘pink’, ‘lawngreen’, ‘indigo’]