[GRASS-SVN] r54993 - grass/trunk/gui/wxpython/wxplot
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Feb 10 06:57:09 PST 2013
Author: martinl
Date: 2013-02-10 06:57:09 -0800 (Sun, 10 Feb 2013)
New Revision: 54993
Modified:
grass/trunk/gui/wxpython/wxplot/base.py
grass/trunk/gui/wxpython/wxplot/dialogs.py
grass/trunk/gui/wxpython/wxplot/scatter.py
Log:
wxGUI: fix scatter plot
Modified: grass/trunk/gui/wxpython/wxplot/base.py
===================================================================
--- grass/trunk/gui/wxpython/wxplot/base.py 2013-02-10 00:49:30 UTC (rev 54992)
+++ grass/trunk/gui/wxpython/wxplot/base.py 2013-02-10 14:57:09 UTC (rev 54993)
@@ -365,9 +365,9 @@
"""!Draw line and point plot from list plot elements.
"""
self.plot = plot.PlotGraphics(plotlist,
- self.ptitle,
- self.xlabel,
- self.ylabel)
+ self.ptitle,
+ self.xlabel,
+ self.ylabel)
if self.properties['x-axis']['prop']['type'] == 'custom':
self.client.SetXSpec('min')
Modified: grass/trunk/gui/wxpython/wxplot/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/wxplot/dialogs.py 2013-02-10 00:49:30 UTC (rev 54992)
+++ grass/trunk/gui/wxpython/wxplot/dialogs.py 2013-02-10 14:57:09 UTC (rev 54993)
@@ -206,9 +206,8 @@
def OnSelection(self, event):
"""!Select raster maps for scatterplot. Must select maps in pairs.
"""
- self.rasterList = []
- self.rasterList = event.GetString().split(',')
-
+ self.rasterList = event.GetString().split(',', 1)
+
def OnSetBins(self, event):
"""!Bins for histogramming FP maps (=nsteps in r.stats)
"""
@@ -217,6 +216,22 @@
def OnSetScattertypes(self, event):
self.scattertype = event.GetString()
+ def GetRasterPairs(self):
+ """!Get raster pairs"""
+ pairsList = list()
+ pair = list()
+ for r in self.rasterList:
+ pair.append(r)
+ if len(pair) == 2:
+ pairsList.append(tuple(pair))
+ pair = list()
+
+ return list(pairsList)
+
+ def GetSettings(self):
+ """!Get type and bins"""
+ return self.scattertype, self.bins
+
class PlotStatsFrame(wx.Frame):
def __init__(self, parent, id, message = '', title = '',
style = wx.DEFAULT_FRAME_STYLE, **kwargs):
Modified: grass/trunk/gui/wxpython/wxplot/scatter.py
===================================================================
--- grass/trunk/gui/wxpython/wxplot/scatter.py 2013-02-10 00:49:30 UTC (rev 54992)
+++ grass/trunk/gui/wxpython/wxplot/scatter.py 2013-02-10 14:57:09 UTC (rev 54993)
@@ -25,7 +25,7 @@
from wxplot.base import BasePlotFrame, PlotIcons
from gui_core.toolbars import BaseToolbar, BaseIcons
from wxplot.dialogs import ScatterRasterDialog, PlotStatsFrame
-from core.gcmd import RunCommand, GException, GError
+from core.gcmd import RunCommand, GException, GError, GMessage
class ScatterFrame(BasePlotFrame):
"""!Mainframe for displaying bivariate scatter plot of two raster maps. Uses wx.lib.plot.
@@ -75,7 +75,10 @@
self.SetGraphStyle()
self.SetupScatterplot()
p = self.CreatePlotList()
- self.DrawPlot(p)
+ if p:
+ self.DrawPlot(p)
+ else:
+ GMessage(_("Nothing to plot."), parent = self)
def OnSelectRaster(self, event):
"""!Select raster map(s) to profile
@@ -83,40 +86,22 @@
dlg = ScatterRasterDialog(parent = self)
if dlg.ShowModal() == wx.ID_OK:
- rlist = dlg.rasterList
- if rlist < 2:
- dlg.Destroy()
- return # need at least 2 rasters for scatterplot
-
- self.bins = dlg.bins # bins for r.stats with float and dcell maps
- self.scattertype = dlg.scattertype # scatterplot or bubbleplot
- self.rasterList = self.CreatePairs(rlist) # list of raster pairs (tuples)
+ self.rasterList = dlg.GetRasterPairs()
+ if not self.rasterList:
+ GMessage(_("At least 2 raster maps must be specified"), parent = dlg)
+ return
+
+ # scatterplot or bubbleplot
+ # bins for r.stats with float and dcell maps
+ self.scattertype, self.bins = dlg.GetSettings()
self.raster = self.InitRasterPairs(self.rasterList, 'scatter') # dictionary of raster pairs
-
+
# plot histogram
- if len(self.rasterList) > 0:
+ if self.rasterList:
self.OnCreateScatter(event = None)
-
+
dlg.Destroy()
- def CreatePairs(self, rlist):
- """!Transforms list of rasters into tuples of raster pairs
- """
- rasterList = []
- next = 'first'
- for r in rlist:
- if next == 'first':
- first = r
- next = 'second'
- else:
- second = r
- t = (first, second)
- rasterList.append(t)
- next = 'first'
- first = second = ''
-
- return rasterList
-
def SetupScatterplot(self):
"""!Build data list for ploting each raster
"""
@@ -209,16 +194,17 @@
"""
# graph the cell value, frequency pairs for the histogram
self.plotlist = []
-
+
for rpair in self.rasterList:
if 'datalist' not in self.raster[rpair] or \
- self.raster[rpair]['datalist'] == None: return
+ self.raster[rpair]['datalist'] is None:
+ continue
if len(self.raster[rpair]['datalist']) > 0:
col = wx.Colour(self.raster[rpair]['pcolor'][0],
- self.raster[rpair]['pcolor'][1],
- self.raster[rpair]['pcolor'][2],
- 255)
+ self.raster[rpair]['pcolor'][1],
+ self.raster[rpair]['pcolor'][2],
+ 255)
scatterpoints = plot.PolyMarker(self.raster[rpair]['datalist'],
legend = ' ' + self.raster[rpair]['plegend'],
colour = col,size = self.raster[rpair]['psize'],
@@ -226,18 +212,18 @@
marker = self.raster[rpair]['ptype'])
self.plotlist.append(scatterpoints)
-
- if len(self.plotlist) > 0:
- return self.plotlist
- else:
- return None
-
+
+ return self.plotlist
+
def Update(self):
"""!Update histogram after changing options
"""
self.SetGraphStyle()
p = self.CreatePlotList()
- self.DrawPlot(p)
+ if p:
+ self.DrawPlot(p)
+ else:
+ GMessage(_("Nothing to plot."), parent = self)
def OnRegression(self, event):
"""!Displays regression information in messagebox
More information about the grass-commit
mailing list