![](/img/trans.png)
[英]%matplotlib inline versus %matplotlib notebook display problems in pythonAnywhere jupyter
[英]Matplotlib Object Oriented Code to display inline in the notebook
關於如何獲取此代碼的任何想法
# -*- 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')
從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方法。 因此,我完全迷失了如何獲取這些令人討厭的,面向對象的圖以內嵌方式呈現。
要顯示不存在於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.