[英]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. 我试图在我的图形中添加一些自定义行为和属性,但是在确定有效(和Pythonic)方法时遇到了麻烦。
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 我的第一个冲动是简单地将
matplotlib.figure.Figure
子类化,但是我不知道该如何实现:我通常会创建新的图形并以类似以下内容开始绘图
fig, ax = matplotlib.pyplot.subplots()
and I can't figure out how this would work with a custom Figure
subclass. 而且我不知道如何使用自定义
Figure
子类。
How can I subclass Figure
in a way that still lets me use pyplot
methods like the one above? 我怎么能子类
Figure
的方式,仍然让我用pyplot
方法类似上面? 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. subplots
其他关键字参数,这些参数直接传递给figures()
,其中之一是用于创建图形的类。
class MyFigure(Figure):
pass
fig, ax = matplotlib.pyplot.subplots(FigureClass=MyFigure)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.