不居中时无法访问matplotlib title fontsize

2024-04-24 20:59:40 发布

您现在位置:Python中文网/ 问答频道 /正文

不知道这里发生了什么。如果设置loc='left'loc='right'get_fontsize方法不再指向非居中标题。你知道吗

如何访问左对齐标题的字体大小?你知道吗

import matplotlib.pyplot as plt

# Set up a blank plot
fig, ax = plt.subplots()

# Set title with fontsize of 30 
ax.set_title('test_title', loc='left', fontsize=30)

# fontsize of title is 12.0? 
print ax.title.get_fontsize()

12.0

Tags: of方法importright标题gettitleplt
1条回答
网友
1楼 · 发布于 2024-04-24 20:59:40

docs

Set one of the three available axes titles. The available titles are positioned above the axes in the center, flush with the left edge, and flush with the right edge.

所以,有3个不同的标题。当您执行dir(ax)时,您会注意到有'_left_title''_right_title'。所以:

fig, ax = plt.subplots()
ax.set_title('test_title', loc='left', fontsize=30)
print ax._left_title.get_fontsize()

30.0

相关问题 更多 >