在用 matplotlib plot 用 marker 时,如果 marker 超出边界,会被截掉,如:
想让边界上的 marker 也显示完整,在 plot 时设置 clip_on=False
,效果:
Code
import os
import numpy as np
import matplotlib
matplotlib.use("Agg")
matplotlib.rcParams['text.usetex'] = True
import matplotlib.pyplot as plt
DATASET = ["flickr", "nuswide"]
MODE = ["i2t", "t2i"]
LABEL = ["$I\\rightarrow T$", "$T\\rightarrow I$"]
MARKER = "os"
X = [3, 4, 5, 6, 7]
data = {
"i2t": [0.6907, 0.7058, 0.7225, 0.73, 0.7373],
"t2i": [0.6804, 0.7127, 0.7294, 0.7379, 0.7313],
}
font = {
'family' : 'Times New Roman',
'weight' : 'normal',
'size' : 18,
}
fig = plt.figure()
for _mode, _marker, _label in zip(MODE, MARKER, LABEL):
plt.plot(X, data[_mode], marker=_marker, label=_label, clip_on=False) # 此处设置
ax = plt.gca()
# ax.set_aspect(0.5 / ax.get_data_ratio(), adjustable='box')
for tick in ax.xaxis.get_major_ticks():
tick.label.set_fontsize(20)
for tick in ax.yaxis.get_major_ticks():
tick.label.set_fontsize(20)
plt.xlim((X[0], X[-1]))
# plt.ylim((0, 1.01))
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
# plt.xlabel("x, font)
plt.ylabel("y", font)
plt.grid()
plt.legend(fontsize=20, loc="best")
plt.tight_layout()
fig.savefig('after.png', pad_inches=0.0)
fig.savefig('after.pdf', pad_inches=0.0, backend='pgf')
plt.close(fig)