简体   繁体   中英

How to set the Figure title, not the ax title when using pandas plot?

After using pandas df.plot , I want to set the title of the whole figure, not the title inside the figure, how to achieve this?

The following two codes explain my question better:

I want to add title here:

lst = [[1, 2], [2, 3], [3, 4]]
plt.figure("I want the title here!")
plt.plot([0, 1, 2], lst)
plt.show()

How to achieve this when using df.plot ?

lst = [[1, 2], [2, 3], [3, 4]]
df = pd.DataFrame(lst)
ax = df.plot()
ax.set_title("not the title here")
plt.show()

You can return an axis object from df.plot(**kwargs) , and use get_figure() to get the figure object, then set the figure title.

ax = df.plot()
ax.get_figure().canvas.set_window_title('Is this the title you want?')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM