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

I am using a custom shape class in pyplot call subplot()

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

and would like to use the axis object ax, usually returned subplot(), in the constructor in a custom shape class. For example, I would like to take this axis and double 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 (which will be returned as) axhere. For example, use gca()results in an empty figure and an "additional" axis; when used get_axes()lead to errors (this is an empty list).

Is there any way to get the axis that will be returned subplotsinside the constructor for the created shape?

+2

Source: https://habr.com/ru/post/1568676/


All Articles