简体   繁体   中英

How do I subclass matplotlib's figure class?

I'm trying to add some custom behaviors and properties to my figures, but I'm having trouble deciding on an effective (and Pythonic) approach.

My first impulse is to simply subclass matplotlib.figure.Figure but I can't figure out how to accomplish this: I generally create new figures and start my plotting with something like

fig, ax = matplotlib.pyplot.subplots()

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

How can I subclass Figure in a way that still lets me use pyplot methods like the one above? Is subclassing even the right way to get custom behaviors associated with a figure? Are the better approaches?

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

class MyFigure(Figure):
    pass

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

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