[英]How can I add "secondary" labels with different font sizes to axes in Matplotlib?
一般的方法是使用ax.annotate()
但對於 x 軸,我們可以簡單地使用子圖標題:
import matplotlib.pyplot as plt
fig, ax = plt.subplots(3,3,sharex=True,sharey=True,
constrained_layout=False, figsize=(10, 6))
x_titles = list("DEF")
y_titles = list("ABC")
for curr_title, curr_ax in zip(x_titles, ax[0, :]):
curr_ax.set_title(curr_title, fontsize=15)
for curr_title, curr_ax in zip(y_titles, ax[:, 0]):
#the xy coordinates are in % axes from the lower left corner (0,0) to the upper right corner (1,1)
#the xytext coordinates are offsets in pixel to prevent
#that the text moves in relation to the axis when resizing the window
curr_ax.annotate(curr_title, xy=(0, 0.5), xycoords="axes fraction",
xytext=(-80, 0), textcoords='offset pixels',
fontsize=15, rotation="vertical")
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.