[英]Matplotlib Object Oriented Code to display inline in the notebook
Any ideas on how I can get this code 关于如何获取此代码的任何想法
# -*- 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')
from the matplotlib example gallery at this link to show me the chart in-line in my notebook? 从matplotlib示例库中的此链接中,可以向我显示笔记本中的在线图表?
Please Note: 请注意:
%matplotlib inline
or %matplotlib notebook
magic %matplotlib inline
或%matplotlib notebook
魔术,可以使基于pyplot的图在笔记本中内联呈现没有问题 This confusing Object Oriented API of matplotlib isn't necessarily rendering inline. matplotlib的这种令人困惑的面向对象的API不一定是内联的。
Should I be using a different canvas? 我应该使用其他画布吗?
Using fig.show() gives me the following error 使用fig.show()给我以下错误
AttributeError: 'FigureCanvasAgg' object has no attribute 'manager' Figure.show works only for figures managed by pyplot, normally created by pyplot.figure().
Also, this particular canvas doesn't have a show method. 另外,此特定画布没有show方法。 So I am totally lost on how to get these darn Obj Oriented plots to render inline.
因此,我完全迷失了如何获取这些令人讨厌的,面向对象的图以内嵌方式呈现。
To display a figure which does not live in pyplot and has no figure manager associated with it, you can use IPython.core.display
: 要显示不存在于pyplot中并且没有与其关联的图形管理器的图形,可以使用
IPython.core.display
:
from IPython.core.display import display
display(fig)
%matplotlib inline import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([1, 2, 3]) ax.set_title('hi mom') ax.grid(True) ax.set_xlabel('time') ax.set_ylabel('volts');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.