Can I get the axis that will be returned by `pyplot.subplots` inside the constructor for the figure it creates?

那年仲夏 提交于 2019-12-02 06:32:51

问题


I'm using a custom figure class in a call to pyplot's subplot()

fig, ax = matplotlib.pyplot.subplots(FigureClass=MyFigure)

and would like to use the axis object(s), ax, normally returned by subplot(), in the constructor to the custom figure class. For example, I'd like to take that axis and twin it:

class MyFigure(matplotlib.figure.Figure):

    def __init__(self, *args, **kwargs):
        super(MyFigure, self).__init__(**kwargs)

        self.ax_one = self.method_that_gets_the_ax_returned_by_subplots()
        self.ax_two = self.ax_one.twinx()
        self.ax_three = self.ax_one.twinx()

but I can't find a way to get (what will be returned as) ax here. Using gca() results in a blank figure and an "extra" axis, for example; while using get_axes() results in errors (it's an empty list).

Is there a way to get the axis that will be returned by subplots inside the constructor for the figure it creates?

来源:https://stackoverflow.com/questions/27473683/can-i-get-the-axis-that-will-be-returned-by-pyplot-subplots-inside-the-constru

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!