的折舊從https://gist.github.com/pklaus/3e16982d952969eb8a9a嵌入matplotlib圖形集成到QT GUI我有以下代碼:pyqt5,matplotlib2和axes.hold
# https://gist.github.com/pklaus/3e16982d952969eb8a9a
class MatplotlibCanvas(FigureCanvas):
"""Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.)."""
def __init__(self, mystacker, spectrum_id, parent=None, width=5, height=4, dpi=100):
self.stacker = mystacker
self.spectrum_id = spectrum_id
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)
self.compute_initial_figure()
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
def compute_initial_figure(self):
spectrumplot.plot_spectrum(self.stacker, self.spectrum_id, self.axes)
但隨着新版本matplotlib 2,我得到以下警告:
MatplotlibDeprecationWarning: axes.hold is deprecated. See the API Changes document (http://matplotlib.org/api/api_changes.html) for more details.
http://matplotlib.org/api/api_changes.html說
「hold」關鍵字參數以及與 相關的所有函數和方法以及「axes.hold」rcParams條目都已棄用。 行爲將與默認保持=真實狀態 一直保持一致。除了使用函數或關鍵字 自變量(hold = False)更改該行爲外,在後續繪製命令之前,請根據需要明確清除軸或圖。
在我的情況下,「根據需要明確清除軸或圖」的正確調用是什麼?
我只是假設'保持(假)'圖形需要在調整大小時正確重繪。但事實證明,如果沒有'hold(False)',它會按預期工作(重新創建軸並選擇適當的刻度標記)。我會暫時放棄它,並引入一個'self.axes.clear()',如果我遇到任何問題。 – mnagel