Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7d5925

Browse files
committed
added get_clim to scalar mappable
svn path=/trunk/matplotlib/; revision=2716
1 parent 19bd05a commit b7d5925

2 files changed

Lines changed: 42 additions & 96 deletions

File tree

examples/wxcursor_demo.py

Lines changed: 38 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,70 @@
1-
#!/usr/bin/env python
21
"""
3-
Show how to have wx draw a cursor over an axes that moves with the
4-
mouse and reports the data coords
2+
Example to draw a cursor and report the data coords in wx
53
"""
64

7-
from matplotlib.numerix import arange, sin, pi
8-
95
import matplotlib
10-
matplotlib.use('WXAgg')
116
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
127
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
13-
148
from matplotlib.figure import Figure
9+
from matplotlib.numerix import arange, sin, pi
1510

16-
from wxPython.wx import *
11+
import wx
1712

18-
class CanvasFrame(wxFrame):
13+
class CanvasFrame(wx.Frame):
1914

20-
def __init__(self):
21-
wxFrame.__init__(self,None,-1,
15+
def __init__(self, ):
16+
wx.Frame.__init__(self,None,-1,
2217
'CanvasFrame',size=(550,350))
2318

24-
self.SetBackgroundColour(wxNamedColor("WHITE"))
19+
self.SetBackgroundColour(wx.NamedColor("WHITE"))
2520

2621
self.figure = Figure()
2722
self.axes = self.figure.add_subplot(111)
2823
t = arange(0.0,3.0,0.01)
2924
s = sin(2*pi*t)
3025

3126
self.axes.plot(t,s)
32-
self.axes.set_xlabel('Time (s)')
33-
self.axes.set_ylabel('Price ($)')
34-
self.canvas = FigureCanvas(self, -1, self.figure)
35-
self.canvas.mpl_connect('motion_notify_event', self.mouse_move)
36-
self.sizer = wxBoxSizer(wxVERTICAL)
37-
self.sizer.Add(self.canvas, 1, wxLEFT | wxTOP | wxGROW)
27+
self.axes.set_xlabel('t')
28+
self.axes.set_ylabel('sin(t)')
29+
self.figure_canvas = FigureCanvas(self, -1, self.figure)
30+
31+
# Note that event is a MplEvent
32+
self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateStatusBar)
33+
self.figure_canvas.Bind(wx.EVT_ENTER_WINDOW, self.ChangeCursor)
34+
35+
self.sizer = wx.BoxSizer(wx.VERTICAL)
36+
self.sizer.Add(self.figure_canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
3837
self.SetSizer(self.sizer)
3938
self.Fit()
4039

41-
self.statusBar = wxStatusBar(self, -1)
40+
self.statusBar = wx.StatusBar(self, -1)
4241
self.statusBar.SetFieldsCount(1)
4342
self.SetStatusBar(self.statusBar)
4443

45-
self.add_toolbar() # comment this out for no toolbar
46-
47-
EVT_PAINT(self, self.OnPaint)
48-
49-
50-
def mouse_move(self, event):
51-
self.draw_cursor(event)
44+
self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
45+
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
46+
self.toolbar.Show()
5247

53-
def add_toolbar(self):
54-
self.toolbar = NavigationToolbar2Wx(self.canvas)
55-
self.toolbar.Realize()
56-
tw, th = self.toolbar.GetSizeTuple()
57-
fw, fh = self.canvas.GetSizeTuple()
58-
self.toolbar.SetSize(wxSize(fw, th))
59-
self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND)
60-
# update the axes menu on the toolbar
61-
self.toolbar.update()
48+
def ChangeCursor(self, event):
49+
self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))
6250

63-
def OnPaint(self, event):
64-
self.erase_cursor()
65-
try: del self.lastInfo
66-
except AttributeError: pass
67-
self.canvas.draw()
68-
event.Skip()
51+
def UpdateStatusBar(self, event):
52+
if event.inaxes:
53+
x, y = event.xdata, event.ydata
54+
self.statusBar.SetStatusText(( "x= " + str(x) +
55+
" y=" +str(y) ),
56+
0)
6957

70-
def draw_cursor(self, event):
71-
'event is a MplEvent. Draw a cursor over the axes'
72-
if event.inaxes is None:
73-
self.erase_cursor()
74-
try: del self.lastInfo
75-
except AttributeError: pass
76-
return
77-
canvas = self.canvas
78-
figheight = canvas.figure.bbox.height()
79-
ax = event.inaxes
80-
left,bottom,width,height = ax.bbox.get_bounds()
81-
bottom = figheight-bottom
82-
top = bottom - height
83-
right = left + width
84-
x, y = event.x, event.y
85-
y = figheight-y
86-
87-
dc = wxClientDC(canvas)
88-
dc.SetLogicalFunction(wxXOR)
89-
wbrush = wxBrush(wxColour(255,255,255), wxTRANSPARENT)
90-
wpen = wxPen(wxColour(200, 200, 200), 1, wxSOLID)
91-
dc.SetBrush(wbrush)
92-
dc.SetPen(wpen)
93-
94-
dc.ResetBoundingBox()
95-
dc.BeginDrawing()
96-
97-
x, y, left, right, bottom, top = [int(val) for val in x, y, left, right, bottom, top]
98-
99-
self.erase_cursor()
100-
line1 = (x, bottom, x, top)
101-
line2 = (left, y, right, y)
102-
self.lastInfo = line1, line2, ax, dc
103-
dc.DrawLine(*line1) # draw new
104-
dc.DrawLine(*line2) # draw new
105-
dc.EndDrawing()
106-
107-
time, price = event.xdata, event.ydata
108-
self.statusBar.SetStatusText("Time=%f Price=%f"% (time, price), 0)
109-
110-
def erase_cursor(self):
111-
try: lastline1, lastline2, lastax, lastdc = self.lastInfo
112-
except AttributeError: pass
113-
else:
114-
lastdc.DrawLine(*lastline1) # erase old
115-
lastdc.DrawLine(*lastline2) # erase old
116-
117-
class App(wxApp):
58+
class App(wx.App):
11859

11960
def OnInit(self):
12061
'Create the main window and insert the custom frame'
12162
frame = CanvasFrame()
122-
frame.Show(true)
123-
124-
return true
125-
126-
app = App(0)
127-
app.MainLoop()
128-
63+
self.SetTopWindow(frame)
64+
frame.Show(True)
65+
return True
66+
67+
if __name__=='__main__':
68+
matplotlib.use('WXAgg')
69+
app = App(0)
70+
app.MainLoop()

lib/matplotlib/cm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def get_array(self):
6969
'Return the array'
7070
return self._A
7171

72+
def get_clim(self):
73+
'return the min, max of the color limits for image scaling'
74+
return self.norm.vmin, self.norm.vmax
75+
7276
def set_clim(self, vmin=None, vmax=None):
7377
'set the norm limits for image scaling'
7478
if vmin is not None: self.norm.vmin = vmin

0 commit comments

Comments
 (0)