首页 > 解决方案 > how to Change matplotlib.figure.Figure objects axis names

问题描述

I have matplotlib.figure.Figure object named as fig1 and which contains

>>> fig1

enter image description here

Now that I wants to change Y ( axis secondary) name from

Bad probability

to

Event probability

I also wants to change title from

Hour

to

Hours to Event

but i could not find how to achive that. There are several solution present on stack overflow like

How to set X and Y axis Title in matplotlib.pyplot

but they explains changing plot title while creating graph where as i am having graph object already created and I just wants to change axis names and title

标签: python-3.xpandasmatplotlib

解决方案


As far I can see, I suppose you plot two axes on the same figure with twinx(). If you want to change the labels of the last created axis (in your case the line plot) than you can use the gca() shortcut (Get Current Axes) to set the label as follows:

fig1.gca().set_ylabel("Event probability")

The figure title can be set with:

fig1.suptitle("Hours to Event")

推荐阅读