Hi,
We have been working on a python wx app GUI for finding and
selecting metadata (lots of lists and check boxes) from a test (that later
fetches SQL time-history data for further processing in LabView or elsewhere).
As an afterthought, we decided to add in a small function
that would allow previewing (plotting) of time-history data based on the
selected metadata. The objective is to have a window pop up with the plotted
time history data and allow the user to zoom, scroll etc, without closing or
exiting the original GUI for selecting the metadata. The reason I want a pop up
window is because I don’t want to change the original metadata selection GUI
(it’s too complicated)
What I’ve done so far is:
Added a button to the metadata GUI called “plot”.
In the “OnPlotButton” event handler I embedded the plotting code.
The “plot” button works fine when I click it the
first time. However, problems occur when I decide to plot a different set of
data (without starting over the metadata GUI). I’d like to choose some
new metadata, then click on the plot button again. But as of present, this
causes the figure to show a gray image (no lines plotted) and then both GUIs
hang up. I’ve tried closing the figure manually prior to selecting new
metadata and clicking on “plot” but it still causes the metadata
GUI to lock up.
Based on what I’ve been reading regarding MPL, it
seems that the matplotlib show() function causes another instance of a GUI loop
to remain suspended.
Is there any way to get the pop-up figure to show the time-history
data and remain interactive (zoom, scroll, etc) and be able to re-plot or “replace”
the current plot? I thought about using the draw() function but I couldn’t
get it to “pop-up” the figure. Also, if I’m not mistaken, the
draw() function doesn’t allow for interactive control?
I think this issue is similar to the issue described here: http://mail.python.org/pipermail/pythonmac-sig/2005-March/013365.html
but I can’t seem to find a simple solution, without embedding the plot
figure directly into the existing GUI (not something easy to do as I’m
not a very experienced Python programmer)
Please let me know if anyone can help.
Here is my code:
def OnPlotButton(self, event):
global SelTestID,
SelRunList, SelEventID, SelChanList, SelCycList
if
self.notebook.GetSelection() == 0:
SelTestID = self.listCtrlStatus.GetItem(0,1).GetText()#.strip(",
“).split(”, ")
if self.listCtrlStatus.GetItem(2,0).GetText() == "Event Selected: ":
SelRunList = self.listCtrlStatus.GetItem(1,1).GetText().strip(",
“).split(”, ")
SelChanList = []
SelCycList = []
SelEventID = self.listCtrlStatus.GetItem(2,1).GetText()#.strip(",
“).split(”, ")
else:
if self.listCtrlStatus.GetItem(1,1).GetText() == “All”:
SelRunList = []
for iRun in range(self.checkListRuns.GetItemCount()):
SelRunList.append(str(self.checkListRuns.GetItemText(iRun)))
else:
SelRunList = self.listCtrlStatus.GetItem(1,1).GetText().strip(",
“).split(”, ")
SelChanList = self.checkListBoxChans.GetCheckedStrings()
if self.listCtrlStatus.GetItem(3,1).GetText() == “All”:
SelCycList = []
else:
SelCycList = self.listCtrlStatus.GetItem(3,1).GetText().strip(",
“).split(”, ")
SelEventID = ‘’
elif
self.notebook.GetSelection() == 1:
SelTestID = self.listCtrlStatus.GetItem(0,1).GetText()#.strip(",
“).split(”, ")
SelRunList = self.listCtrlStatus.GetItem(1,1).GetText().strip(",
“).split(”, ")
SelChanList = []
SelCycList = []
SelEventID = ‘’
##VTS.MsgBox("Test","eWO:
" + SelTestID + "\nRuns: " + str(SelRunList) + "\nChans:
" + str(SelChanList) + "\nCycles: " + str(SelCycList) +
"\nEvent: " + SelEventID)
#cleanup to
prevent memory leak if previously plotted
plt.close('all')
##make sure all figure windows are closed
fig = []
ax = []
#prep data for
plotting plotting
myeWO =
str(SelTestID)
nRuns =
len(SelRunList)
myRuns = []
for iRuns in
range(nRuns):
myRuns.append(str(SelRunList[iRuns]))
nChans =
len(SelChanList)
myChans = []
for iChan in
range(nChans):
myChans.append(str(SelChanList[iChan]))
dataLst =
VTS.FetchSQLRunDataByName(myeWO, myRuns, myChans)
lenData =
len(dataLst)
dataArry =
np.zeros((lenData, nChans + 1))
for iPoint in
range(lenData):
dataArry[iPoint] = dataLst[iPoint]
#begin plotting
fig =
plt.figure(1)
ax =
fig.add_subplot(111)
myPlotLines = []
for iChan in
range(nChans):
tempLine, = ax.plot(dataArry[:,0], dataArry[:,iChan+1], label = myChans[iChan])
myPlotLines.append(tempLine)
myTitle =
plt.title('eWO: ’ + myeWO + '\nRun IDs: ’ + str(myRuns))
ax.grid('on')
##plt.legend(loc=0)
myLegend =
plt.legend(loc=0)
legTxt =
myLegend.get_texts() ##get legent text
plt.setp(legTxt,
fontsize=‘small’) ##set legend text fontsize to small
myXLabel =
plt.xlabel(‘Time (s)’)
##VTS.MsgBox(“Test”,"eWO: " + SelTestID + "\neWO type:
" + str(type(SelTestID)) + "\nRuns: " + str(myRuns) +
"\nnRuns " + str(nRuns) + "\nChans: " + str(myChans) +
"\nnChans: " + str(nChans) + "\nEvent: " + SelEventID)
plt.show()
event.Skip()
Krishna ** ** Adrianto Pribadi****
Test Engineer
Desk (TTF): 256.480.4450
Cell: 412.401.1477
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands (VTS)
This communication (including any attachments) is for the use of the intended recipient(s) only and may contain information that is confidential, privileged or otherwise legally protected. Any unauthorized use or dissemination of this communication is prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail message and delete all copies of the original communication. Thank you for your cooperation