0

I'm trying to make a GUI that contains several figures, each with an axes (is 'axes' plural?). 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. 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.

Later in the code, I called self.leftImage.set_data(newSlide), but nothing seems to change even though it definitely gets executed. I tried setting leftImage to a new instance of imshow(), but that doesn't seem to fix anything.

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.

David
  • 877
  • 1
  • 7
  • 18

1 Answers1

0

You should use draw() just after your update (done with set_data()).

See this related post for detail https://stackoverflow.com/a/17837600/4716013

Community
  • 1
  • 1
prodev_paris
  • 495
  • 1
  • 4
  • 17
  • Calling `plt.draw()` right after the update doesn't do anything. I'm honestly not entirely sure what it does in the first place since the first image seems to be displayed without calling anything other than `imshow()`. – David Jul 07 '15 at 13:40
  • Okay, apparently calling `self.leftPlot.draw()` actually does something. But now it's like the plot itself has some sort of 'stamping' effect, like the previous modifications seem to remain despite updating the graph. I'm not sure where the problem lies, but I think it's something that warrants another question. I'll accept your post since you're the only person here. – David Jul 07 '15 at 13:51
  • @david there is several info (tutorial) at http://matplotlib.org/users/image_tutorial.html and also specialy about [`imshow()`](http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.imshow) – prodev_paris Jul 07 '15 at 14:00
  • Thanks for the link, but I actually figured out that it's just an oversight. I just had to call `np.copy()` since I forgot arrays are mutable in Python. – David Jul 07 '15 at 14:10
  • @david otherwise you may have call something like `.remove()` so that in the code sample you provide it may looks like `self.leftImage.remove()` – prodev_paris Jul 07 '15 at 14:13