可以先清空窗口内容
plt.clf() # 清空图片
plt.close() # 清空窗口
跟matlab的plot操作是一样的,记得加上show才可以看到,可以画多个曲线一起,主要是一些参数的设置对图像有需要
1图形颜色线条设置可以参看:https://blog.csdn.net/kkxgx/article/details/6951959,画出的点都是实心的,空心的点得用plt.scatter(x[i], y[i], color='', marker='o', edgecolors='g', s=200) # 把 corlor 设置为空,通过edgecolors来控制颜色,设置,然后再加上线,网址https://blog.csdn.net/alanguoo/article/details/79184267
plt.plot(x, y1, 'g->', x, y2,'r-o',linewidth=1)
plt.show()
2线的粗细是linewidth=w控制,柱状填充,没有使用过,参看:https://blog.csdn.net/weixin_34613450/article/details/81744440
3设置x轴和y轴的范围和名字:
plt.axis([x1,x2,y1,y2])#设置范围
plt.xlabel('Rnak score')#设置x轴名字
plt.ylabel('Matching Rate(%)')#设置y轴名字
4设置网格线,默认是灰色实线,可以选择其他线型和颜色
plt.grid()#默认
plt.grid(linestyle=':')#其他线型,可以是'-','--','-.',':','|',linestyle也可以用ls取代
plt.grid(axis=,color=,ls=,linewidth=)#分别是哪个axis的网格线,颜色,线型,线宽
5坐标轴间隔,这个找不到简单的方法,就是刻度,参考:https://blog.csdn.net/Fortware/article/details/51934814
from pylab import * #这个库用来调用subplot
from matplotlib.ticker import MultipleLocator
a = subplot(111)#指定图片
xmajorLocator = MultipleLocator(2)#x轴设定为2的倍数
ymajorLocator = MultipleLocator(5)#y轴设定为5的倍数
a.xaxis.set_major_locator(xmajorLocator)#实现在图像a上
a.xaxis.set_major_locator(ymajorLocator)
有两种标注方法,一种是直接在plt.plot画曲线时候选择label=,适合用在只有几条线,另一种对plt.plot取出对应的曲线进行操作
(1)直接label,会产生对应的图标,需要加上plt.legend,不过不能修改名字,可以修改位置
,就是对应的数字
plt.plot(x, y1, 'g->',label='ResNet-50(Saliency)',linewidth=1)
plt.plot(x, y2,'r-o',label='ResNet-50(class)',linewidth=1)
plt.legend(loc=4)
位置信息:
loc=int
loc code | 表示信息 |
0 | ‘best’ |
1 | ‘upper right’ 右上角 |
2 | ‘upper left’ 左上角 |
3 | ‘lower left’ 左下角 |
4 | ‘lower right’ 右下角 |
5 | ‘right’ 右边 |
6 | ‘center left’ 中间左边 |
7 | ‘center right’ 中间右边 |
8 | ‘lower center’ 中间下边 |
9 | ‘center’ 中间 |
(2)在legend那边设置label的值
l1, = plt.plot(x, y1, label = 'line')
l2, = plt.plot(x, y2, label = 'parabola')
plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 'best')
曲线光滑插值:https://blog.csdn.net/huozi07/article/details/50538749
具体参数参考官方网站:https://docs.scipy.org/doc/scipy-0.19.0/reference/generated/scipy.interpolate.interp1d.html
x为x轴的点,y为y轴的点,生成函数f1,f2,f3, ……,然后让x或者new_x进入函数,生成平滑后的y1,y2,y3或者new_y1,new_y2,new_y3
f1=interp1d(x,y,kind='nearest')#临近插值
f2=interp1d(x,y,kind='zero')#0阶插值
f3=interp1d(x,y,kind='linear')#线性插值,或者选择slinear
f4=interp1d(x,y,kind='quadratic')#二次样条插值
f5=interp1d(x,y,kind='cubic')#三次样条插值
y1=f1(x)
y2=f2(x)
y3=f3(x)
……
对应图片