0

I'm running into an issue when trying to call up matplotlib figures from a PyQt GUI. The figures themselves display fine, but as soon as they appear I get an ugly blank grey screen behind both my GUI and figure. This does not go away until I have closed the GUI.

Here's the section of my GUI in which I call the function, in another script, that should display my graph. I would post the whole thing but it's quite long.

def readSignal(self):
    signal = self.buttonGroup.checkedId() #reads integer signal from analysis options
    timeStamps,deltaPix,fps=motionTools.loadData(self.filenames+"/")

    if signal == 1:
        motionTools.motionInROI(timeStamps,deltaPix)
    elif signal == 2:
        motionTools.barTimeInROI(deltaPix)
    else:
        self.analysisOptionError.show()

Both of these motionTools functions use the data (timeStamps and deltaPix are slices of arrays, fps is a frames-per-second integer) to generate different graphs. Here's an example of one of them (barTimeInROI) - both cause this grey screen error.

# bar graph of total time and pixels in each ROI
deltaPix = deltaPix[:,1:] # get rid of background columns

frameRate = getFrameRate()

rows,cols = deltaPix.shape

pixSums = np.sum(deltaPix, axis=0)
deltaPix[deltaPix>0]=1 # convert pixels to time moving
timeSums = np.sum(deltaPix, axis=0) / frameRate

f, (ax1, ax2) = plt.subplots(2, sharex=True)

ax1.bar(np.arange(cols) + 1, pixSums, align='center')
ax2.bar(np.arange(cols) + 1, timeSums, align='center')

plt.xlabel('ROI number', fontsize=18)
plt.xlim(0,cols+1)

ax1.set_ylabel('Locomotion \n(displaced pixels)', fontsize=18, va='center')
ax1.yaxis.labelpad = 25
ax2.set_ylabel('Locomotion  \n(seconds with motion)', fontsize=18, va='center')
ax2.yaxis.labelpad = 25

f.set_facecolor('w')
plt.tick_params(axis='both', which='major', labelsize=18)

if cols < 21:
    plt.xticks(np.arange(1, cols+1, 1))
else:
    plt.xticks(np.arange(1, cols+1, 5))
plt.show()

Any ideas? Will I have to embed the matplotlib graphs in the interface?

Emily C
  • 281
  • 2
  • 4
  • 9
  • Yes, I advise to embed your graphs as demonstrated in [this example](http://matplotlib.org/examples/user_interfaces/embedding_in_qt4.html). – titusjan May 15 '15 at 09:58
  • BTW: most of the code you've posted is not relevant to the problem. You said the whole thing is too large to post, so that's why you should strip it down to a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). If that link doesn't convince you, you may also want to read an answer of mine [here](http://stackoverflow.com/a/30013567/625350), which shows the benefits of an MCVE in practice. Posting a screen shot might also be useful in your case. – titusjan May 15 '15 at 10:11

0 Answers0