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

Skip to content

Commit d86a504

Browse files
committed
fixed numerous little bugs in gtk and gd and updated examples to new API
svn path=/trunk/matplotlib/; revision=115
1 parent f734644 commit d86a504

8 files changed

Lines changed: 83 additions & 44 deletions

File tree

API_CHANGES

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,47 @@ API changes at 0.50
1616

1717
Migrating code:
1818

19-
There are no API changes for the matlab interface.
20-
21-
There is one important API change for application developers.
22-
Figure instances used subclass GUI widgets that enabled them to be
23-
placed directly into figures. Eg, FigureGTK subclassed
24-
gtk.DrawingArea. Now the Figure class is independent of the
25-
backend, and FigureCanvas takes over the functionality formerly
26-
handled by Figure. In order to include figures into your apps, you
27-
now need to do, for example
28-
29-
# gtk example
30-
fig = Figure(figsize=(5,4), dpi=100)
31-
canvas = FigureCanvasGTK(fig) # a gtk.DrawingArea
32-
canvas.show()
33-
vbox.pack_start(canvas)
34-
35-
Apologies for the inconvenience. This refactorization brings
36-
significant more freedom in developing matplotlib and should bring
37-
better plotting capabilities, so I hope the inconvenience is worth
38-
it.
19+
Matlab interface:
20+
21+
The only API change for those using the matlab interface is in how
22+
you call figure redraws for dynamically updating figures. In the
23+
old API, you did
24+
25+
fig.draw()
26+
27+
In the new API, you do
28+
29+
manager = get_current_fig_manager()
30+
manager.canvas.draw()
31+
32+
See the examples system_monitor.py, dynamic_demo.py, and anim.py
33+
34+
API
35+
36+
There is one important API change for application developers.
37+
Figure instances used subclass GUI widgets that enabled them to be
38+
placed directly into figures. Eg, FigureGTK subclassed
39+
gtk.DrawingArea. Now the Figure class is independent of the
40+
backend, and FigureCanvas takes over the functionality formerly
41+
handled by Figure. In order to include figures into your apps,
42+
you now need to do, for example
43+
44+
# gtk example
45+
fig = Figure(figsize=(5,4), dpi=100)
46+
canvas = FigureCanvasGTK(fig) # a gtk.DrawingArea
47+
canvas.show()
48+
vbox.pack_start(canvas)
49+
50+
If you use the NavigationToolbar, this in now intialized with a
51+
FigureCanvas, not a Figure. The examples embedding_in_gtk.py,
52+
embedding_in_gtk2.py, and mpl_with_glade.py all reflect the new
53+
API so use these as a guide.
54+
55+
Apologies for the inconvenience. This refactorization brings
56+
significant more freedom in developing matplotlib and should bring
57+
better plotting capabilities, so I hope the inconvenience is worth
58+
it.
59+
3960

4061

4162
API changes at 0.42

KNOWN_BUGS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ KNOWN BUGS
2222
- x and y ticklabels overlap at origin
2323

2424
- parse error on lines like plot(bins, mu, bins, mu+sigma, '--')
25+
26+
GD
27+
28+
- right tickline is off
29+
30+
- dashes not scaling with dpi properly - rounding error or other?
31+
32+
33+

examples/dynamic_demo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
X = rand(len(ind),10)
1111
lines = plot(X[:,0], 'o')
1212

13+
manager = get_current_fig_manager()
1314
def updatefig(*args):
1415
lines[0].set_data(ind, X[:,updatefig.count])
15-
fig.draw()
16+
manager.canvas.draw()
1617
updatefig.count += 1
1718
if updatefig.count<10: return gtk.TRUE
1819
else: return gtk.FALSE
1920

2021
updatefig.count = 0
2122

22-
gtk.timeout_add(1000, updatefig)
23+
gtk.timeout_add(300, updatefig)
2324
show()
2425

2526

examples/mpl_with_glade.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import matplotlib
22
matplotlib.use('GTK')
33

4+
from matplotlib.figure import Figure
45
from matplotlib.axes import Subplot
5-
from matplotlib.backends.backend_gtk import FigureGTK, NavigationToolbar
6+
from matplotlib.backends.backend_gtk import FigureCanvasGTK, NavigationToolbar
67

78
from Numeric import arange, sin, pi
89
import gtk
@@ -37,21 +38,22 @@ def __init__(self):
3738
self.widgets = gtk.glade.XML('mpl_with_glade.glade')
3839
self.widgets.signal_autoconnect(GladeHandlers.__dict__)
3940

40-
self.figure = FigureGTK(figsize=(8,6), dpi=72)
41-
self.figure.show()
41+
self.figure = Figure(figsize=(8,6), dpi=72)
4242
self.axis = Subplot(self.figure, 111)
4343
self.figure.add_axis(self.axis)
4444
t = arange(0.0,3.0,0.01)
4545
s = sin(2*pi*t)
4646
self.axis.plot(t,s)
4747
self.axis.set_xlabel('time (s)')
4848
self.axis.set_ylabel('voltage')
49-
50-
self['vboxMain'].pack_start(self.figure, gtk.TRUE, gtk.TRUE)
49+
50+
self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
51+
self.canvas.show()
52+
self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
5153
self['vboxMain'].show()
5254

5355
# below is optional if you want the navigation toolbar
54-
self.navToolbar = NavigationToolbar(self.figure, self['windowMain'])
56+
self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
5557
self.navToolbar.lastDir = '/var/tmp/'
5658
self['vboxMain'].pack_start(self.navToolbar)
5759
self.navToolbar.show()

examples/object_picker.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
import matplotlib
1111
matplotlib.use('GTK')
1212

13-
from matplotlib.backends.backend_gtk import FigureGTK, NavigationToolbar, \
14-
error_msg, colorManager
13+
from matplotlib.backends.backend_gtk import NavigationToolbar, \
14+
error_msg, colorManager, FigureCanvasGTK
1515
from matplotlib.axes import Subplot
1616

17+
from matplotlib.figure import Figure
1718
from matplotlib.lines import Line2D, lineStyles, lineMarkers
1819
from matplotlib.transforms import Bound2D
1920
from matplotlib.patches import draw_bbox
@@ -201,10 +202,10 @@ def run(self):
201202
break
202203
self.destroy()
203204

204-
class ArtistPickerFigure(FigureGTK):
205+
class PickerCanvas(FigureCanvasGTK):
205206

206207
def button_press_event(self, widget, event):
207-
width, height = self.renderer.gdkDrawable.get_size()
208+
width, height = self.figure.renderer.gdkDrawable.get_size()
208209

209210
self.pick(event.x, height-event.y)
210211

@@ -225,10 +226,10 @@ def pick(self, x, y, epsilon=5):
225226
"""
226227

227228
clickBBox = Bound2D(x-epsilon/2, y-epsilon/2, epsilon, epsilon)
228-
draw_bbox(self.dpi, clickBBox, self.renderer)
229+
draw_bbox(self.figure.dpi, clickBBox, self.figure.renderer)
229230

230231
def over_text(t):
231-
bbox = t.get_window_extent(self.renderer)
232+
bbox = t.get_window_extent(self.figure.renderer)
232233
return clickBBox.overlap(bbox)
233234

234235
def over_line(line):
@@ -239,9 +240,9 @@ def over_line(line):
239240
distances = sqrt((x-xdata)**2 + (y-ydata)**2)
240241
return min(distances)<epsilon
241242

242-
for ax in fig.axes:
243+
for ax in self.figure.axes:
243244

244-
for line in ax._lines:
245+
for line in ax.get_lines():
245246
if over_line(line):
246247
self.select_line(line)
247248
return
@@ -265,17 +266,21 @@ def over_line(line):
265266
win.add(vbox)
266267
vbox.show()
267268

268-
fig = ArtistPickerFigure(figsize=(5,4), dpi=100)
269+
fig = Figure(figsize=(5,4), dpi=100)
270+
269271
ax = Subplot(fig, 111)
270272
t = arange(0.0,3.0,0.01)
271273
s = sin(2*pi*t)
272274

273275
ax.plot(t,s)
276+
ax.set_title('click on line or text')
274277
fig.add_axis(ax)
275-
fig.show()
276-
vbox.pack_start(fig)
277278

278-
toolbar = NavigationToolbar(fig, win)
279+
canvas = PickerCanvas(fig)
280+
canvas.show()
281+
vbox.pack_start(canvas)
282+
283+
toolbar = NavigationToolbar(canvas, win)
279284
toolbar.show()
280285
vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE)
281286

examples/pcolor_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def func3(x,y):
1616
pcolor(X, Y, Z, shading='flat')
1717
#axis([-3, 3, -3, 3])
1818
#axis('off')
19-
#savefig('pcolor_demo')
19+
savefig('pcolor_demo')
2020
show()
2121

2222

examples/subplot_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def f(t):
2121
xlabel('time (s)')
2222
ylabel('Undamped')
2323

24-
savefig('subplot_demo',dpi=300)
24+
savefig('subplot_demo')
2525
show()
2626

examples/system_monitor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ def get_stats():
3434
ax.set_ylabel('Percent usage')
3535
ax.set_title('System Monitor')
3636

37+
manager = get_current_fig_manager()
3738
def updatefig(*args):
3839
m,c,n = get_stats()
3940
pm.set_height(m)
4041
pc.set_height(c)
4142
pn.set_height(n)
4243
ax.set_ylim([0,100])
4344

44-
fig.draw()
45-
45+
manager.canvas.draw()
46+
4647
return gtk.TRUE
4748

4849

0 commit comments

Comments
 (0)