简体   繁体   English

图形未更新(matplotlib)

[英]Graphs not updating (matplotlib)

I'm trying to make a GUI that contains several figures, each with an axes (is 'axes' plural?). 我正在尝试制作一个包含多个图形的GUI,每个图形都有一个轴(“轴”是复数?)。 I managed to get the leftmost graph to plot upon initializing the respective widget using this line: 在使用以下行初始化各个窗口小部件时,我设法获得了最左侧的图形:

    self.leftImage = self.leftPlot.axes.imshow(self.defaultSlide, cmap = self.mymap)

where self.leftPlot contains the necessary figure properties. 其中self.leftPlot包含必要的图形属性。 I noticed that I didn't have to call plt.show() or its variants for this part, which I don't know whether it's significant or not. 我注意到我不必为此部分调用plt.show()或其变体,我不知道它是否有意义。

Later in the code, I called self.leftImage.set_data(newSlide) , but nothing seems to change even though it definitely gets executed. 在代码的更高版本中,我调用了self.leftImage.set_data(newSlide) ,但是即使肯定执行了,似乎也没有任何改变。 I tried setting leftImage to a new instance of imshow() , but that doesn't seem to fix anything. 我尝试将leftImage设置为imshow()的新实例,但这似乎无法解决任何问题。

My imports: 我的进口:

from PySide import QtCore, QtGui
from PySide.QtCore import *
from PySide.QtGui import *
import matplotlib

matplotlib.use('Qt4Agg')
matplotlib.rcParams['backend.qt4']='PySide'

from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt

I'm fairly new to matplotlib, but I do come from a MATLAB background if that helps. 我对matplotlib相当陌生,但如果有帮助,我确实来自MATLAB背景。

You should use draw() just after your update (done with set_data() ). 您应该在更新后立即使用draw() (通过set_data() )。

See this related post for detail https://stackoverflow.com/a/17837600/4716013 有关详细信息,请参见此相关文章https://stackoverflow.com/a/17837600/4716013

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM