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

Skip to content

Commit e1b8eca

Browse files
committed
fixed layer images bug
svn path=/trunk/matplotlib/; revision=402
1 parent 9c2d9c3 commit e1b8eca

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
New entries should be added at the top
22

3+
2004-07-14 Fixed layer images demo which was broken by the 07/12 image
4+
extent fixes - JDH
5+
36
2004-07-13 Modified line collections to handle arbitrary length
47
segments for each line segment. - JDH
58

examples/embedding_in_wx2.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
"""
3-
An example of how to use wx or wxagg in an application w/o the toolbar
3+
An example of how to use wx or wxagg in an application w. or w/o the toolbar
44
"""
55

66
from matplotlib.numerix import arange, sin, pi
@@ -14,6 +14,7 @@
1414
# comment out the following to use wx rather than wxagg
1515
matplotlib.use('WXAgg')
1616
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
17+
from matplotlib.backends.backend_wx import NavigationToolbarWx as NavigationToolbar
1718

1819
from matplotlib.figure import Figure
1920

@@ -27,7 +28,7 @@ def __init__(self):
2728

2829
self.SetBackgroundColour(wxNamedColor("WHITE"))
2930

30-
self.figure = Figure(figsize=(5,4), dpi=100)
31+
self.figure = Figure()
3132
self.axes = self.figure.add_subplot(111)
3233
t = arange(0.0,3.0,0.01)
3334
s = sin(2*pi*t)
@@ -38,9 +39,35 @@ def __init__(self):
3839

3940
self.sizer = wxBoxSizer(wxVERTICAL)
4041
self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
42+
43+
#self.add_toolbar() # comment this out for no toolbar
44+
45+
4146
# Capture the paint message
4247
EVT_PAINT(self, self.OnPaint)
4348

49+
def add_toolbar(self):
50+
self.toolbar = NavigationToolbar(self.canvas, True)
51+
self.toolbar.Realize()
52+
if wxPlatform == '__WXMAC__':
53+
# Mac platform (OSX 10.3, MacPython) does not seem to cope with
54+
# having a toolbar in a sizer. This work-around gets the buttons
55+
# back, but at the expense of having the toolbar at the top
56+
self.SetToolBar(self.toolbar)
57+
else:
58+
# On Windows platform, default window size is incorrect, so set
59+
# toolbar width to figure width.
60+
tw, th = self.toolbar.GetSizeTuple()
61+
fw, fh = self.canvas.GetSizeTuple()
62+
# By adding toolbar in sizer, we are able to put it at the bottom
63+
# of the frame - so appearance is closer to GTK version.
64+
# As noted above, doesn't work for Mac.
65+
self.toolbar.SetSize(wxSize(fw, th))
66+
self.sizer.Add(self.toolbar, 0, wxLEFT | wxEXPAND)
67+
# update the axes menu on the toolbar
68+
self.toolbar.update()
69+
70+
4471
def OnPaint(self, event):
4572
self.canvas.draw()
4673

examples/layer_images.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ def func3(x,y):
1616
y = arange(-3.0, 3.0, dy)
1717
X,Y = meshgrid(x, y)
1818

19+
# when layering multiple images, the images need to have the same
20+
# extent. This does not mean they need to have the same shape, but
21+
# they both need to render to the same coordinate system determined by
22+
# xmin, xmax, ymin, ymax
23+
24+
xmin, xmax, ymin, ymax = min(x), max(x), min(y), max(y)
25+
extent = xmin, xmax, ymin, ymax
1926
Z1 = array(([0,1]*4 + [1,0]*4)*4); Z1.shape = 8,8 # chessboard
20-
im1 = imshow(Z1, cmap=cm.gray, interpolation='nearest')
27+
im1 = imshow(Z1, cmap=cm.gray, interpolation='nearest',
28+
extent=extent)
2129
hold(True)
2230

2331
Z2 = func3(X, Y)
24-
im2 = imshow(Z2, cmap=cm.jet, alpha=.9, interpolation='bilinear')
32+
im2 = imshow(Z2, cmap=cm.jet, alpha=.9, interpolation='bilinear',
33+
extent=extent)
34+
axis([xmin, xmax, ymin, ymax])
2535

2636

2737
#savefig('layer_images')

0 commit comments

Comments
 (0)