]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/plot.py
wxSscanf() and friends are now Unicode+ANSI friendly wrappers instead of defines...
[wxWidgets.git] / wxPython / wx / lib / plot.py
index 5674c53a5df69b69941361326e1468b9b65fab9c..96827b67c74c8efe2feced5bdcfa37b0fd3b9490 100644 (file)
@@ -94,7 +94,7 @@ import  wx
 
 # Needs Numeric or numarray or NumPy
 try:
 
 # Needs Numeric or numarray or NumPy
 try:
-    import numpy as _Numeric
+    import numpy.oldnumeric as _Numeric
 except:
     try:
         import numarray as _Numeric  #if numarray is used it is renamed Numeric
 except:
     try:
         import numarray as _Numeric  #if numarray is used it is renamed Numeric
@@ -462,11 +462,12 @@ class PlotCanvas(wx.Panel):
     plotting canvas (self.canvas). It allows for simple general plotting
     of data with zoom, labels, and automatic axis scaling."""
 
     plotting canvas (self.canvas). It allows for simple general plotting
     of data with zoom, labels, and automatic axis scaling."""
 
-    def __init__(self, parent):
+    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
+                 size=wx.DefaultSize, style=0, name="plotCanvas"):
         """Constructs a panel, which can be a child of a frame or
         any other non-control window"""
     
         """Constructs a panel, which can be a child of a frame or
         any other non-control window"""
     
-        wx.Panel.__init__(self, parent)
+        wx.Panel.__init__(self, parent, id, pos, size, style, name)
 
         sizer = wx.FlexGridSizer(2,2,0,0)
         self.canvas = wx.Window(self, -1)
 
         sizer = wx.FlexGridSizer(2,2,0,0)
         self.canvas = wx.Window(self, -1)
@@ -553,6 +554,7 @@ class PlotCanvas(wx.Panel):
         self._ySpec= 'auto'
         self._gridEnabled= False
         self._legendEnabled= False
         self._ySpec= 'auto'
         self._gridEnabled= False
         self._legendEnabled= False
+        self._titleEnabled= True
         
         # Fonts
         self._fontCache = {}
         
         # Fonts
         self._fontCache = {}
@@ -566,6 +568,8 @@ class PlotCanvas(wx.Panel):
         self._pointLabelFunc= None
         self.canvas.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
 
         self._pointLabelFunc= None
         self.canvas.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
 
+        self._useScientificNotation = False
+
         self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)
         self.canvas.Bind(wx.EVT_SIZE, self.OnSize)
         # OnSize called to make sure the buffer is initialized.
         self.canvas.Bind(wx.EVT_PAINT, self.OnPaint)
         self.canvas.Bind(wx.EVT_SIZE, self.OnSize)
         # OnSize called to make sure the buffer is initialized.
@@ -745,6 +749,12 @@ class PlotCanvas(wx.Panel):
         """Set True to show scrollbars"""
         return self.sb_vert.IsShown()
 
         """Set True to show scrollbars"""
         return self.sb_vert.IsShown()
 
+    def SetUseScientificNotation(self, useScientificNotation):
+        self._useScientificNotation = useScientificNotation
+
+    def GetUseScientificNotation(self):
+        return self._useScientificNotation
+
     def SetEnableDrag(self, value):
         """Set True to enable drag."""
         if value not in [True,False]:
     def SetEnableDrag(self, value):
         """Set True to enable drag."""
         if value not in [True,False]:
@@ -798,6 +808,17 @@ class PlotCanvas(wx.Panel):
         """True if Legend enabled."""
         return self._legendEnabled
 
         """True if Legend enabled."""
         return self._legendEnabled
 
+    def SetEnableTitle(self, value):
+        """Set True to enable title."""
+        if value not in [True,False]:
+            raise TypeError, "Value should be True or False"
+        self._titleEnabled= value 
+        self.Redraw()
+
+    def GetEnableTitle(self):
+        """True if title enabled."""
+        return self._titleEnabled
+
     def SetEnablePointLabel(self, value):
         """Set True to enable pointLabel."""
         if value not in [True,False]:
     def SetEnablePointLabel(self, value):
         """Set True to enable pointLabel."""
         if value not in [True,False]:
@@ -1037,11 +1058,14 @@ class PlotCanvas(wx.Panel):
         textSize_scale= _Numeric.array([rhsW+lhsW,bottomH+topH]) # make plot area smaller by text size
         textSize_shift= _Numeric.array([lhsW, bottomH])          # shift plot area by this amount
 
         textSize_scale= _Numeric.array([rhsW+lhsW,bottomH+topH]) # make plot area smaller by text size
         textSize_shift= _Numeric.array([lhsW, bottomH])          # shift plot area by this amount
 
-        # drawing title and labels text
-        dc.SetFont(self._getFont(self._fontSizeTitle))
-        titlePos= (self.plotbox_origin[0]+ lhsW + (self.plotbox_size[0]-lhsW-rhsW)/2.- titleWH[0]/2.,
-                 self.plotbox_origin[1]- self.plotbox_size[1])
-        dc.DrawText(graphics.getTitle(),titlePos[0],titlePos[1])
+        # draw title if requested
+        if self._titleEnabled:
+            dc.SetFont(self._getFont(self._fontSizeTitle))
+            titlePos= (self.plotbox_origin[0]+ lhsW + (self.plotbox_size[0]-lhsW-rhsW)/2.- titleWH[0]/2.,
+                       self.plotbox_origin[1]- self.plotbox_size[1])
+            dc.DrawText(graphics.getTitle(),titlePos[0],titlePos[1])
+
+        # draw label text
         dc.SetFont(self._getFont(self._fontSizeAxis))
         xLabelPos= (self.plotbox_origin[0]+ lhsW + (self.plotbox_size[0]-lhsW-rhsW)/2.- xLabelWH[0]/2.,
                  self.plotbox_origin[1]- xLabelWH[1])
         dc.SetFont(self._getFont(self._fontSizeAxis))
         xLabelPos= (self.plotbox_origin[0]+ lhsW + (self.plotbox_size[0]-lhsW-rhsW)/2.- xLabelWH[0]/2.,
                  self.plotbox_origin[1]- xLabelWH[1])
@@ -1130,7 +1154,7 @@ class PlotCanvas(wx.Panel):
             l.append(cn)
         return l
 
             l.append(cn)
         return l
 
-    def GetClosetPoint(self, pntXY, pointScaled= True):
+    def GetClosestPoint(self, pntXY, pointScaled= True):
         """Returns list with
             [curveNumber, legend, index of closest point, pointXY, scaledXY, distance]
             list for only the closest curve.
         """Returns list with
             [curveNumber, legend, index of closest point, pointXY, scaledXY, distance]
             list for only the closest curve.
@@ -1150,6 +1174,8 @@ class PlotCanvas(wx.Panel):
         mdist = min(dists)  #Min dist
         i = dists.index(mdist)  #index for min dist
         return closestPts[i]  #this is the closest point on closest curve
         mdist = min(dists)  #Min dist
         i = dists.index(mdist)  #index for min dist
         return closestPts[i]  #this is the closest point on closest curve
+    
+    GetClosetPoint = GetClosestPoint
 
     def UpdatePointLabel(self, mDataDict):
         """Updates the pointLabel point on screen with data contained in
 
     def UpdatePointLabel(self, mDataDict):
         """Updates the pointLabel point on screen with data contained in
@@ -1246,13 +1272,13 @@ class PlotCanvas(wx.Panel):
         # The Buffer init is done here, to make sure the buffer is always
         # the same size as the Window
         Size  = self.canvas.GetClientSize()
         # The Buffer init is done here, to make sure the buffer is always
         # the same size as the Window
         Size  = self.canvas.GetClientSize()
-        if Size.width <= 0 or Size.height <= 0:
-            return
+        Size.width = max(1, Size.width)
+        Size.height = max(1, Size.height)
         
         # Make new offscreen bitmap: this bitmap will always have the
         # current drawing in it, so it can be used to save the image to
         # a file, or whatever.
         
         # Make new offscreen bitmap: this bitmap will always have the
         # current drawing in it, so it can be used to save the image to
         # a file, or whatever.
-        self._Buffer = wx.EmptyBitmap(Size[0],Size[1])
+        self._Buffer = wx.EmptyBitmap(Size.width, Size.height)
         self._setSize()
 
         self.last_PointLabel = None        #reset pointLabel
         self._setSize()
 
         self.last_PointLabel = None        #reset pointLabel
@@ -1354,8 +1380,11 @@ class PlotCanvas(wx.Panel):
         """Draws Title and labels and returns width and height for each"""
         # TextExtents for Title and Axis Labels
         dc.SetFont(self._getFont(self._fontSizeTitle))
         """Draws Title and labels and returns width and height for each"""
         # TextExtents for Title and Axis Labels
         dc.SetFont(self._getFont(self._fontSizeTitle))
-        title= graphics.getTitle()
-        titleWH= dc.GetTextExtent(title)
+        if self._titleEnabled:
+            title= graphics.getTitle()
+            titleWH= dc.GetTextExtent(title)
+        else:
+            titleWH= (0,0)
         dc.SetFont(self._getFont(self._fontSizeAxis))
         xLabel, yLabel= graphics.getXLabel(),graphics.getYLabel()
         xLabelWH= dc.GetTextExtent(xLabel)
         dc.SetFont(self._getFont(self._fontSizeAxis))
         xLabel, yLabel= graphics.getXLabel(),graphics.getYLabel()
         xLabelWH= dc.GetTextExtent(xLabel)
@@ -1564,7 +1593,7 @@ class PlotCanvas(wx.Panel):
                 error = e
                 factor = f
         grid = factor * 10.**power
                 error = e
                 factor = f
         grid = factor * 10.**power
-        if power > 4 or power < -4:
+        if self._useScientificNotation and (power > 4 or power < -4):
             format = '%+7.1e'        
         elif power >= 0:
             digits = max(1, int(power))
             format = '%+7.1e'        
         elif power >= 0:
             digits = max(1, int(power))
@@ -2020,7 +2049,7 @@ class TestFrame(wx.Frame):
         if self.client.GetEnablePointLabel() == True:
             #make up dict with info for the pointLabel
             #I've decided to mark the closest point on the closest curve
         if self.client.GetEnablePointLabel() == True:
             #make up dict with info for the pointLabel
             #I've decided to mark the closest point on the closest curve
-            dlst= self.client.GetClosetPoint( self.client._getXY(event), pointScaled= True)
+            dlst= self.client.GetClosestPoint( self.client._getXY(event), pointScaled= True)
             if dlst != []:    #returns [] if none
                 curveNum, legend, pIndex, pointXY, scaledXY, distance = dlst
                 #make up dictionary to pass to my user function (see DrawPointLabel) 
             if dlst != []:    #returns [] if none
                 curveNum, legend, pIndex, pointXY, scaledXY, distance = dlst
                 #make up dictionary to pass to my user function (see DrawPointLabel)