How to make a subclass class matplotlib?

I am trying to add some custom behaviors and properties to my shapes, but it's hard for me to decide on an efficient (and Pythonic) approach.

My first impulse is just to subclass matplotlib.figure.Figure, but I can’t figure out how to do it: usually I create new shapes and start my plot with something like

fig, ax = matplotlib.pyplot.subplots()

and I can't figure out how this will work with a custom subclass Figure.

How can I subclass Figurein such a way as to still use methods pyplotsimilar to those described above? Does even subclass the correct way to get custom behavior associated with a figure? Are the best approaches?

+2
source share
1 answer

subplotsaccepts additional keyword arguments that are passed directly to figures(), one of which is the class used to create shapes.

class MyFigure(Figure):
    pass

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

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


All Articles