【发布时间】:2018-01-19 11:22:25
【问题描述】:
关于如何获取此代码的任何想法
# -*- 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')
从this 的 matplotlib 示例库链接中显示我笔记本中的内嵌图表?
请注意:
- 我想避免使用 pyplot,因为我试图仅使用他们的“面向对象”库来使用 matplotlib
- 我可以使用
%matplotlib inline或%matplotlib notebook魔法将基于 pyplot 的绘图以内联方式呈现在我的笔记本中
matplotlib 的这个令人困惑的面向对象 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 方法。所以我完全不知道如何让这些该死的面向对象的图内联渲染。
【问题讨论】:
-
很有趣,昨天有人问了一个类似的问题:stackoverflow.com/questions/45614123/…
标签: python oop matplotlib plot jupyter-notebook