我对这张图表非常满意,除了我无法在行尾插入4个标签,并且将其另存为pdf时看起来也不好。
我已经尝试过在ax.annotate中将figsize更改为figsize =(9,6)和xy =(0.984,y),这是我所能得到的。
我还能做些什么来使右侧的标签更加可见?
我的代码。
import matplotlib.pyplot as plt
import matplotlib.transforms as mtrans
from matplotlib.ticker import FixedLocator, FormatStrFormatter
#%matplotlib notebook
plt.style.use('seaborn-poster')
fig,ax = plt.subplots(figsize=(8,6), facecolor='w', edgecolor='blue')
my_colors=['orangered','seagreen', 'goldenrod', 'darkviolet', 'sienna']
ax.set_ylim(merged.min().min(), merged.max().max())
ax.set_ylim(-0.7, 31)
ax=merged.plot(y=['Kinver', 'Nomads', 'Plough', 'Alveley Royals', 'Alveley Oaks'],marker='o',figsize=(9,6),legend=None, color=my_colors, ax=ax)
selectcols=merged[['Kinver', 'Nomads', 'Plough', 'Alveley Royals', 'Alveley Oaks']]
for line, name in zip(ax.lines, selectcols.columns):
y = line.get_ydata()[-1]
ax.annotate(name, xy=(0.984,y), xytext=(6,0), color=line.get_color(),
xycoords = ax.get_yaxis_transform(), textcoords="offset points",
size=14, va="center")
merged.plot(y='Footloose', marker='o', figsize=(9,6), legend=None, color= 'steelblue', ax=ax, alpha=1,
transform=mtrans.offset_copy(ax.transData, fig=fig, x=0.0, y=4, units='points'))
y = 12
ax.annotate('Footloose', xy=(0.984,y), xytext=(6,0), color='steelblue',
xycoords = ax.get_yaxis_transform(), textcoords="offset points",
size=14, va="center")
merged.plot(y=['Top Pub'], marker='o', figsize=(9,6), legend=None, color= 'darkred', ax=ax, alpha=1,
transform=mtrans.offset_copy(ax.transData, fig=fig, x=0.0, y=3*(1), units='points'))
y = 22
ax.annotate('Top Pub', xy=(0.984,y), xytext=(6,0), color='darkred',
xycoords = ax.get_yaxis_transform(), textcoords="offset points",
size=14, va="center")
y = 2
merged.plot(y='Gaters', marker='o', figsize=(9,6), legend=None, color= 'springgreen', ax=ax, alpha=1,
transform=mtrans.offset_copy(ax.transData, fig=fig, x=0.0, y=-1.8, units='points'))
ax.annotate('Gaters', xy=(0.984,y), xytext=(6,0), color='springgreen',
xycoords = ax.get_yaxis_transform(), textcoords="offset points",
size=14, va="center")
ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
fig.text(0.25, 0.95, "Clubs of", ha="center", va="bottom", size=17,color="black")
fig.text(0.34, 0.95, "S", ha="center", va="bottom", size=21,color="blue")
fig.text(0.37, 0.95, "V", ha="center", va="bottom", size=21,color="red")
fig.text(0.40, 0.95, "P", ha="center", va="bottom", size=21,color="gold")
fig.text(0.43, 0.95, "L", ha="center", va="bottom", size=21,color="darkgreen")
fig.text(0.59, 0.95,"in years 2014-2019", ha="center", va="bottom", size=17,color="black")
x_axis = ax.axes.get_xaxis()
x_label = x_axis.get_label()
x_label.set_visible(False)
ax.set_ylabel('Points won', color='darkblue', fontdict={'fontsize': 14, 'fontweight': 'medium'})
years=[2014,2015, 2016,2017,2018, 2019]
plt.xticks(range(len(years)),(years))
plt.margins(x=0.012,y=0.2)
ax.get_xaxis().tick_bottom()
#ax.get_yaxis().tick_left()
ax.tick_params(axis='y', which='major', labelsize=12,bottom=False, top=False, labelbottom=True,
left=False, right=False, labelright=False)
ax.tick_params(axis='x', which='major', labelsize=14,bottom=False, top=False, labelbottom=True,
left=False, right=False, labelright=False)
#fig.subplots_adjust(left=.06, right=.75, bottom=0, top=.94)
ax.yaxis.set_major_formatter(plt.FuncFormatter('{:.0f}'.format))
ax.grid(True, 'major', 'y', ls='--', lw=.6, c='darkgray', alpha=.5)
plt.show()
plt.savefig('SVPLclubs1.pdf')
谢谢!
fig.subplots_adjust(left = .075,right = .65,bottom = 0,top = .94)帮助了我!