我想在此圖中顯示框架。 我試圖運行下面的代碼,但它沒有工作:如何在matplotlib上繪製框架圖
ax = self.canvas.figure.add_subplot(111)
ax.spines['top'].set_visible(True)
ax.spines['right'].set_visible(True)
ax.spines['bottom'].set_visible(True)
ax.spines['left'].set_visible(True)
ax.plot(diff)
我也試過:
plt.tight_layout()
,但它會產生這個錯誤:
> File "runme.py", line 54, in autocorr_function
> plt.tight_layout() File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line
> 1406, in tight_layout
> fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py",
> line 1753, in tight_layout
> rect=rect) File "/usr/local/lib/python2.7/dist-packages/matplotlib/tight_layout.py",
> line 326, in get_tight_layout_figure
> max_nrows = max(nrows_list) ValueError: max() arg is an empty sequence
您的幫助,將不勝感激, 謝謝。
編輯:這裏是帆布的代碼:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt from PyQt4 import QtGui
class Canvas(FigureCanvas):
def __init__(self, parent=None):
self.figure = plt.figure() #plt.tight_layout(pad=4)
FigureCanvas.__init__(self, self.figure)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
看起來你不是在一個孤立的matplotlib圖中繪製圖,而是在一些GUI的畫布內。我們需要更多信息。 tight_layout是一種在數字框架內伸展軸的圖形方法,它不是關於邊框。 – Wli
我添加了畫布的代碼,希望它更清晰。 –
你需要什麼畫布?爲什麼不使用plt.plot來繪製它(...) – 2Obe