如何,我可以从matplotlib例如画廊在this链接获取此代码Matplotlib面向对象的代码在笔记本内嵌显示
# -*- noplot -*-
"""
=============================
The object-oriented interface
=============================
A pure OO (look Ma, no pylab!) example using the agg backend
"""
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
ax.plot([1, 2, 3])
ax.set_title('hi mom')
ax.grid(True)
ax.set_xlabel('time')
ax.set_ylabel('volts')
向我展示图表内嵌在我的笔记本任何想法?
请注意:
- 我想避免使用pyplot因为我想用自己的“面向对象”库使用matplotlib只
- 我没有问题,得到基于pyplot地块呈现内嵌在我使用matplotlib的
%matplotlib inline
或%matplotlib notebook
魔法
这混乱的面向对象的API笔记本不一定渲染内联。
我应该使用不同的画布吗?
使用fig.show()给了我下面的错误
AttributeError: 'FigureCanvasAgg' object has no attribute 'manager' Figure.show works only for figures managed by pyplot, normally created by pyplot.figure().
而且,这个特殊的画布上没有一个show方法。所以我完全失去了如何让这些dom Obj Oriented绘图呈现内联。
搞怪够有一个类似的问题,就在昨天问:https://stackoverflow.com/questions/45614123/showing-several-figures-at-once – ImportanceOfBeingErnest