import matplotlib.pyplot as plt
import matplotlib
from matplotlib.ticker import MultipleLocator
import numpy as np
y = [52.96, 52.84, 50.62, 55.35, 55.78, 56.03, 57.44, 58.75, 60.82]
y2 =[52.90, 52.90, 52.90, 52.90, 52.90, 52.90, 52.90, 52.90, 52.90]
y3 =[58.90, 58.90, 58.90, 58.90, 58.90, 58.90, 58.90, 58.90, 58.90]
x = ["10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%"]
plt.rcParams["font.family"] = "Times New Roman"
fig, axes = plt.subplots(1, 1, figsize=(8, 4))
# 折线图
l1 = plt.plot(x, y, linestyle='-', color='black', marker='x', linewidth=1.5, label = "SAR-ISAR")
l2 = plt.plot(x, y3, linestyle='-.', color='red', marker='', linewidth=1.5, label = "SAR")
l3 = plt.plot(x, y2, linestyle=':', color='blue', marker='', linewidth=1.5, label = "ISAR")
plt.legend()
# plt.hlines(0, 0, 0.5, colors = "r", linestyles = "dashed")
# 设置最小刻度间隔
# axes.yaxis.set_minor_locator(MultipleLocator(2.5))
# axes.xaxis.set_minor_locator(MultipleLocator(0.5))
# 画网格线
# axes.grid(which='minor', c='lightgrey')
# 设置x、y轴标签
axes.set_ylabel("Accuracy")
axes.set_xlabel("SAR Ratio of SAR-ISAR Data")
# 设置y轴的刻度
# axes.set_yticks([51,52,53,54,55,56,57,58,59,60,61])
# 对每个数据点加标注
for x_, y_ in zip(x, y):
axes.text(x_, y_, y_, ha='left', va='bottom')
axes.text(x[8], y2[8], y2[8], ha='left', va='bottom')
axes.text(x[8], y3[8], y3[8], ha='left', va='bottom')
# 展示图片
plt.show()
fig.savefig("plot.pdf", dpi=800)
[自用代码]画直线图和折线图的代码
于 2020-12-14 16:26:20 首次发布