折线图(Python)

使用matplotlib绘制折线图
示例1
import matplotlib.pyplot as plt
import numpy as np
# 中文显示
plt.rcParams["font.sans-serif"]=["SimHei"] #设置字体
plt.rcParams["axes.unicode_minus"]=False #该语句解决图像中的“-”负号的乱码问题

font = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 15,
}

x = np.arange(1,9)
y1 = [0.7, 0.7, 0.6, 0.5, 0.5, 0.4, 0.4, 0.4]
y2 = [0.8, 0.7, 0.7, 0.6, 0.5, 0.5, 0.4, 0.4]
y3 = [0.6, 0.6, 0.5, 0.5, 0.4, 0.4, 0.4, 0.3]
y4 = [0.8, 0.8, 0.7, 0.6, 0.5, 0.5, 0.4, 0.4]

#绘制折线图,添加数据点,设置点的大小
# * 表示绘制五角星;此处也可以不设置线条颜色,matplotlib会自动为线条添加不同的颜色
plt.plot(x, y1, color='m', marker='.', markersize=10, linestyle='--', linewidth=2.0, clip_on=False)
plt.plot(x, y2, color='g', marker='.',markersize=10, linestyle='-.', linewidth=2.0, clip_on=False)
plt.plot(x, y3, color='c', marker='.', markersize=10, linestyle=':', linewidth=2.0, clip_on=False)
plt.plot(x, y4, color='r', marker='.',markersize=10, linestyle='-', linewidth=2.0, clip_on=False)

# 设置坐标刻度,区间范围
plt.xticks(np.arange(1, 8.1, 1), fontproperties='Times New Roman', size = 13)
plt.yticks(np.arange(0.3, 1.1, 0.1), fontproperties='Times New Roman', size = 13)
plt.xlim((1, 8))
plt.xlabel("Number of pictures", font)  # x轴标题
plt.ylabel("Average RD", font)  # y轴标题

#绘制图例
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 14,
}
plt.legend(['Euclidean', 'Manhattan', "Chebyshev", "Ours"], prop = font1, frameon=False, loc="upper right")

ax = plt.gca()  #gca:get current axis得到当前轴
#设置图片的右边框和上边框为不显示
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.show()
示例2
import matplotlib.pyplot as plt
import numpy as np

plt.rcParams["font.sans-serif"]=["SimHei"] #设置字体
plt.rcParams["axes.unicode_minus"]=False #该语句解决图像中的“-”负号的乱码问题

font = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 15,
}
#准备绘制数据
x = ['dinosaur', 'build', 'plane',	'car','cat', 'flower', 'train', 'tree', 'landscape', 'wolf']
y1 = [0.9,0.3,0.4,0.4,0.9,0.8,0.6,0.7,0.4,0.8]
y2 = [1,0.3,0.3,0.7,1,0.8,0.5,0.7,0.8,0.8]

plt.plot(x, y1, color='#4F94CD', marker='.', markersize=10, linestyle='--', linewidth=2.0, clip_on=False, label='LBP')
plt.plot(x, y2, color='r', marker='.',markersize=10, linestyle='-', linewidth=2.0, clip_on=False, label='IU-LBP')


plt.ylabel("Average RD", font)  # y轴标题
plt.xticks(fontproperties='Times New Roman', size = 13)
plt.yticks(np.arange(0.3, 1.1, 0.1), fontproperties='Times New Roman', size = 13)

font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 14,
}
plt.legend(prop = font1, frameon=False, loc="upper right")

ax = plt.gca()  #gca:get current axis得到当前轴
#设置图片的右边框和上边框为不显示
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值