欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

matplotlib绘图

程序员文章站 2022-03-10 15:47:46
...

matplotlib绘制曲线

#绘制曲线内像素均值变化曲线 数据来自img1index24.png的7次迭代
import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import make_interp_spline

#解决中文显示问题
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False

#数据
x = np.array([1, 2, 3, 4, 5, 6, 7])
c1 = np.array([22.62,23.94736842105263, 26.30532212885154, 29.879811468970935, 35.39802336028751, 41.08150470219436, 45.384934756820876])
cr1 = np.array([254.83, 254.5, 251.84407096171802, 245.52395915161037, 234.83378256963164, 222.1951410658307, 211.7544483985765])
csum = c1+cr1
tag = np.array([255, 255, 255, 255, 255, 255, 255])
#平滑
x_smooth = np.linspace(x.min(), x.max(), 300)
c1_smooth = make_interp_spline(x, c1)(x_smooth)
cr1_smooth = make_interp_spline(x, cr1)(x_smooth)
csum_smooth = make_interp_spline(x, csum)(x_smooth)
tag_smooth = make_interp_spline(x, tag)(x_smooth)
#画线
plt.plot(x_smooth, c1_smooth, label="c1")
plt.plot(x_smooth, cr1_smooth, label="cr1")
plt.plot(x_smooth, csum_smooth, label="csum")
plt.plot(x_smooth, tag_smooth, c='black', label="255")
plt.legend(loc="best") #loc="upper left"
#x,y轴名称
plt.xlabel("迭代次数")
plt.ylabel("灰度值")
#标题
# plt.title("我是标题")
plt.show()
'''
plt.legend()loc=
'best' : 0,          
 'upper right'  : 1,
 'upper left'   : 2,
 'lower left'   : 3,
 'lower right'  : 4,
 'right'        : 5,
 'center left'  : 6,
 'center right' : 7,
 'lower center' : 8,
 'upper center' : 9,
 'center'       : 10,
'''