我有一個 matplotlib 圖,圖例中有一個標題,還有我想控制的標題文本的屬性,比如字體系列大小等。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
font = font_manager.FontProperties(family='Comic Sans MS',
weight='bold',
style='normal',
size=32)
fig,ax = plt.subplots()
x = np.linspace(0,2*np.pi)
# plot lines
linu1,= ax.plot(x,np.sin(x),label='u$_1$', linewidth=2)
ax.legend(title="My Title", prop=font)
# set axes labels, labelpad is offset of the label from the axis
ax.set_xlabel(r'$y (\AA)$ ', fontsize=21,fontdict={'fontsize': 8, 'fontweight': 'medium','fontname':"Serif"})
ax.set_ylabel('x', fontsize=21)
plt.show()
圖例選項中的prop引數只控制行的文本,而不是標題(即“我的標題”)。如何更改標題文本的屬性?
uj5u.com熱心網友回復:
標題具有標題的專用屬性,用于指定設定。
ax.legend(title="My Title", title_fontproperties=font, prop=font)

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/474866.html
標籤:Python matplotlib
