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

Skip to content

Commit ad809df

Browse files
committed
added subplot tool to toolbar in gtk*, wx* and tk
svn path=/trunk/matplotlib/; revision=1466
1 parent 026a72e commit ad809df

17 files changed

+472
-50
lines changed

API_CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
API Changes in matplotlib-0.82
2+
3+
Added subplot config tool to GTK* backends -- note you must now
4+
import the NavigationToolbar2 from your backend of choice rather
5+
than from backend_gtk because it needs to know about the backend
6+
specific canvas -- see examples/embedding_in_gtk2.py. Ditto for wx
7+
backend -- see examples/embedding_in_wxagg.py
8+
19
API CHANGES in matplotlib-0.81.1
210

311
Sean Richards notes there was a problem in the way we created the

CHANGELOG

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
New entries should be added at the top
22

3+
2005-06-15 Added subplot config tool to GTK* backends -- note you must
4+
now import the NavigationToolbar2 from your backend of
5+
choice rather than from backend_gtk because it needs to
6+
know about the backend specific canvas -- see
7+
examples/embedding_in_gtk2.py. Ditto for wx backend -- see
8+
examples/embedding_in_wxagg.py
9+
310
2005-06-15 backend_cairo.py: updated to use pycairo 0.5.0 - SC
411

512
2005-06-14 Wrote some GUI neutral widgets (Button, Slider,
6-
RadioButton) in matplotlib.widgets. See examples/widgets -
7-
JDH
13+
RadioButtons, CheckButtons) in matplotlib.widgets. See
14+
examples/widgets/*.py - JDH
815

916
2005-06-14 Exposed subplot parameters as rc vars and as the fig
1017
SubplotParams instance subplotpars. See

examples/embedding_in_gtk2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
1616

1717
# or NavigationToolbar for classic
18-
from matplotlib.backends.backend_gtk import NavigationToolbar2GTK as NavigationToolbar
18+
from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar
1919

2020
from matplotlib.axes import Subplot
2121
from matplotlib.figure import Figure

examples/embedding_in_wx4.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
# comment out the following to use wx rather than wxagg
1616
matplotlib.use('WXAgg')
1717
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
18-
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
18+
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg
1919

2020
from matplotlib.backends.backend_wx import _load_bitmap
2121
from matplotlib.figure import Figure
2222
from matplotlib.numerix.mlab import rand
2323

2424
from wxPython.wx import *
2525

26-
class MyNavigationToolbar(NavigationToolbar2Wx):
26+
class MyNavigationToolbar(NavigationToolbar2WxAgg):
2727
"""
2828
Extend the default wx toolbar with your own event handlers
2929
"""
3030
ON_CUSTOM = wxNewId()
3131
def __init__(self, canvas, cankill):
32-
NavigationToolbar2Wx.__init__(self, canvas)
32+
NavigationToolbar2WxAgg.__init__(self, canvas)
3333

3434
# for simplicity I'm going to reuse a bitmap from wx, you'll
3535
# probably want to add your own.

images/subplots.png

1.05 KB
Loading

images/subplots.ppm

1.74 KB
Binary file not shown.

images/subplots.xpm

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/* XPM */
2+
static char * subplots_xpm[] = {
3+
"24 24 218 2",
4+
" c None",
5+
". c #000000",
6+
"+ c #2C2C2C",
7+
"@ c #3B3B3B",
8+
"# c #004300",
9+
"$ c #007300",
10+
"% c #F2F2F2",
11+
"& c #F4F4F4",
12+
"* c #F3F3F3",
13+
"= c #F1F1F1",
14+
"- c #A9A9A9",
15+
"; c #3C583C",
16+
"> c #48D848",
17+
", c #58DC58",
18+
"' c #479447",
19+
") c #6F6F6F",
20+
"! c #ECECEC",
21+
"~ c #D8D8D8",
22+
"{ c #858585",
23+
"] c #3A3A3A",
24+
"^ c #CFCFCF",
25+
"/ c #B7B7B7",
26+
"( c #B9B9B9",
27+
"_ c #374037",
28+
": c #3AC13A",
29+
"< c #62D562",
30+
"[ c #79DA79",
31+
"} c #5FD45F",
32+
"| c #2F5E2F",
33+
"1 c #BBBBBB",
34+
"2 c #C2C2C2",
35+
"3 c #C5C5C5",
36+
"4 c #161616",
37+
"5 c #393939",
38+
"6 c #CDCDCD",
39+
"7 c #A5A5A5",
40+
"8 c #808080",
41+
"9 c #383838",
42+
"0 c #202020",
43+
"a c #686868",
44+
"b c #D9D9D9",
45+
"c c #CACACA",
46+
"d c #A0A0A0",
47+
"e c #6686A5",
48+
"f c #518FCC",
49+
"g c #5694CF",
50+
"h c #5B98D1",
51+
"i c #609DD4",
52+
"j c #65A1D6",
53+
"k c #6AA6D9",
54+
"l c #6FAADB",
55+
"m c #75AFDE",
56+
"n c #7AB3E1",
57+
"o c #7FB8E3",
58+
"p c #91C3E8",
59+
"q c #A3CEED",
60+
"r c #CFE6F6",
61+
"s c #373737",
62+
"t c #C8C8C8",
63+
"u c #6888A6",
64+
"v c #5693CE",
65+
"w c #47759E",
66+
"x c #32506B",
67+
"y c #34526C",
68+
"z c #37546D",
69+
"A c #39576E",
70+
"B c #3C5970",
71+
"C c #3E5B71",
72+
"D c #7CA2BE",
73+
"E c #ADD4EF",
74+
"F c #A9D3EF",
75+
"G c #D2E8F7",
76+
"H c #353535",
77+
"I c #9A9A9A",
78+
"J c #303030",
79+
"K c #39526A",
80+
"L c #5A98D1",
81+
"M c #29435C",
82+
"N c #1F1F1F",
83+
"O c #2E2E2E",
84+
"P c #191919",
85+
"Q c #2A2D48",
86+
"R c #141414",
87+
"S c #242424",
88+
"T c #586B78",
89+
"U c #AED7F1",
90+
"V c #4D5860",
91+
"W c #5A5A5A",
92+
"X c #171717",
93+
"Y c #314E31",
94+
"Z c #32BA32",
95+
"` c #2C3F51",
96+
" . c #5F9CD3",
97+
".. c #848484",
98+
"+. c #ACACAC",
99+
"@. c #656565",
100+
"#. c #6F7DA9",
101+
"$. c #565656",
102+
"%. c #AAAAAA",
103+
"&. c #999999",
104+
"*. c #0B0D0F",
105+
"=. c #B2DAF3",
106+
"-. c #3A6242",
107+
";. c #44B144",
108+
">. c #000900",
109+
",. c #0C460C",
110+
"'. c #3ECD3E",
111+
"). c #5BCE5B",
112+
"!. c #2E4152",
113+
"~. c #64A0D6",
114+
"{. c #8D8D8D",
115+
"]. c #6A6A6A",
116+
"^. c #95AFCD",
117+
"/. c #5F5F5F",
118+
"(. c #A2A2A2",
119+
"_. c #B6DDF5",
120+
":. c #47664F",
121+
"<. c #6EE16E",
122+
"[. c #0D930D",
123+
"}. c #002600",
124+
"|. c #001900",
125+
"1. c #0D9D0D",
126+
"2. c #52D252",
127+
"3. c #76D576",
128+
"4. c #2F4253",
129+
"5. c #69A4D8",
130+
"6. c #7F7F7F",
131+
"7. c #BAE1F7",
132+
"8. c #4B6753",
133+
"9. c #8FEA8F",
134+
"0. c #21A121",
135+
"a. c #00A600",
136+
"b. c #0C160C",
137+
"c. c #63D063",
138+
"d. c #314353",
139+
"e. c #6EA8DA",
140+
"f. c #FFFFFF",
141+
"g. c #BDE4F9",
142+
"h. c #37633F",
143+
"i. c #8BE98B",
144+
"j. c #0E5A0E",
145+
"k. c #4C4C4C",
146+
"l. c #308130",
147+
"m. c #324554",
148+
"n. c #89BAE2",
149+
"o. c #C0E6FA",
150+
"p. c #38593F",
151+
"q. c #457745",
152+
"r. c #333333",
153+
"s. c #B6B6B6",
154+
"t. c #6D6D6D",
155+
"u. c #5C768C",
156+
"v. c #8BBCE4",
157+
"w. c #191C1E",
158+
"x. c #181D1F",
159+
"y. c #C2E9FC",
160+
"z. c #95A4AB",
161+
"A. c #BFBFBF",
162+
"B. c #7C99B0",
163+
"C. c #8DBFE5",
164+
"D. c #92A6B5",
165+
"E. c #181C1E",
166+
"F. c #A0BECD",
167+
"G. c #C4ECFE",
168+
"H. c #E1F5FF",
169+
"I. c #EFEFEF",
170+
"J. c #7E9BB1",
171+
"K. c #8FC1E7",
172+
"L. c #C0DDF2",
173+
"M. c #C3E0F4",
174+
"N. c #C6E2F5",
175+
"O. c #C8E4F6",
176+
"P. c #C8E5F7",
177+
"Q. c #C8E6F8",
178+
"R. c #C8E8F9",
179+
"S. c #C7E9FB",
180+
"T. c #C7EBFC",
181+
"U. c #C6ECFE",
182+
"V. c #C4EDFF",
183+
"W. c #E0F5FF",
184+
"X. c #819DB2",
185+
"Y. c #92C4E9",
186+
"Z. c #BBDBF2",
187+
"`. c #4B575F",
188+
" + c #30383D",
189+
".+ c #31393E",
190+
"++ c #323A3E",
191+
"@+ c #3B454A",
192+
"#+ c #A2BFCD",
193+
"$+ c #C8EDFE",
194+
"%+ c #C6EDFF",
195+
"&+ c #C2ECFF",
196+
"*+ c #DFF5FF",
197+
"=+ c #F0F0F0",
198+
"-+ c #B8B8B8",
199+
";+ c #E7E7E7",
200+
">+ c #4B554B",
201+
",+ c #4FD34F",
202+
"'+ c #7BE87B",
203+
")+ c #9BF09B",
204+
"!+ c #78E778",
205+
"~+ c #407040",
206+
"{+ c #8C8C8C",
207+
"]+ c #DADADA",
208+
"^+ c #DBDBDB",
209+
"/+ c #A8A8A8",
210+
"(+ c #385438",
211+
"_+ c #4DD64D",
212+
":+ c #60DB60",
213+
"<+ c #459145",
214+
"[+ c #767676",
215+
"}+ c #DFDFDF",
216+
"|+ c #E0E0E0",
217+
"1+ c #E1E1E1",
218+
"2+ c #E2E2E2",
219+
"3+ c #0B0B0B",
220+
"4+ c #003900",
221+
"5+ c #017301",
222+
" ",
223+
" ",
224+
" . . ",
225+
" . + @ . . . . . # $ . . . . . . . . ",
226+
" + % & & * = - ; > , ' ) ! ! ! ~ ~ { . ",
227+
" ] ^ / ( ( ( _ : < [ } | { 1 1 2 3 3 4 ",
228+
" 5 6 7 8 8 8 9 0 0 0 0 + a 8 8 8 8 b . ",
229+
" 9 c d e f g h i j k l m n o p q r ! . ",
230+
" s t d u v h w x y z A B C D E F G ! . ",
231+
" H I J K L M N O P Q Q R + S T U V W . ",
232+
" X Y Z ` .. ..+.@.#.#.$.%.&.*.=.-.;.>. ",
233+
" . ,.'.).!.~.. {.%.].^.^./.+.(.. _.:.<.[.}. ",
234+
" |.1.2.3.4.5.. 6.6.6.6.6.6.6.6.. 7.8.9.0.a.. ",
235+
" b.;.c.d.e.. f.f.f.f.f.f.f.f.. g.h.i.j.. ",
236+
" N k.l.m.n.. f.f.f.f.f.f.f.f.. o.p.q.. ",
237+
" r.s.t.u.v.w.^ f.f.f.f.f.f.^ x.y.z.%.. ",
238+
" r.A.(.B.C.D.E.. . . . . . x.F.G.H.I.. ",
239+
" r.A.(.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.I.. ",
240+
" r.A.(.X.Y.Z.`. +.+.+++@+#+$+%+&+*+=+. ",
241+
" P A.-+;+f.f.>+,+'+)+!+~+/ f.f.f.f.=+. ",
242+
" . {+^ ]+]+^+/+(+_+:+<+[+}+|+|+1+1+2+. ",
243+
" 3+. . . . . . 4+5+. . . . . . . 9 . ",
244+
" . . ",
245+
" "};

lib/matplotlib/backends/backend_gtk.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
1616
from matplotlib.numerix import asarray, fromstring, UInt8, zeros, \
1717
where, transpose, nonzero, indices, ones, nx
1818
import matplotlib.numerix as numerix
19+
from matplotlib.widgets import SubplotTool
1920

2021
from backend_gdk import RendererGDK
2122

@@ -404,15 +405,8 @@ def __init__(self, canvas, num):
404405
self.canvas.show()
405406
self.vbox.pack_start(self.canvas, True, True)
406407

407-
# must be inited after the window, drawingArea and figure
408-
# attrs are set
409-
if matplotlib.rcParams['toolbar']=='classic':
410-
self.toolbar = NavigationToolbar (canvas, self.window)
411-
elif matplotlib.rcParams['toolbar']=='toolbar2':
412-
self.toolbar = NavigationToolbar2GTK (canvas, self.window)
413-
else:
414-
self.toolbar = None
415-
408+
self.toolbar = self._get_toolbar(canvas)
409+
416410
# calculate size for window
417411
w = int (self.canvas.figure.bbox.width())
418412
h = int (self.canvas.figure.bbox.height())
@@ -444,6 +438,17 @@ def destroy(self, *args):
444438
if Gcf.get_num_fig_managers()==0 and not matplotlib.is_interactive():
445439
gtk.main_quit()
446440

441+
def _get_toolbar(self, canvas):
442+
# must be inited after the window, drawingArea and figure
443+
# attrs are set
444+
if matplotlib.rcParams['toolbar']=='classic':
445+
toolbar = NavigationToolbar (canvas, self.window)
446+
elif matplotlib.rcParams['toolbar']=='toolbar2':
447+
toolbar = NavigationToolbar2GTK (canvas, self.window)
448+
else:
449+
toolbar = None
450+
return toolbar
451+
447452

448453

449454
class NavigationToolbar2GTK(NavigationToolbar2, gtk.Toolbar):
@@ -456,6 +461,7 @@ class NavigationToolbar2GTK(NavigationToolbar2, gtk.Toolbar):
456461
('Pan', 'Pan axes with left mouse, zoom with right', 'move.png','pan'),
457462
('Zoom', 'Zoom to rectangle','zoom_to_rect.png', 'zoom'),
458463
(None, None, None, None),
464+
('Subplots', 'Configure subplots','subplots.png', 'configure_subplots'),
459465
('Save', 'Save the figure','filesave.png', 'save_figure'),
460466
)
461467

@@ -594,6 +600,30 @@ def save_figure(self, button):
594600
fname = self.fileselect.get_filename_from_user()
595601
if fname:
596602
self.canvas.print_figure(fname)
603+
604+
def configure_subplots(self, button):
605+
toolfig = Figure(figsize=(6,3))
606+
canvas = self._get_canvas(toolfig)
607+
toolfig.subplots_adjust(top=0.9)
608+
tool = SubplotTool(self.canvas.figure, toolfig)
609+
610+
w = int (toolfig.bbox.width())
611+
h = int (toolfig.bbox.height())
612+
613+
614+
window = gtk.Window()
615+
window.set_title("Subplot Configuration Tool")
616+
window.set_default_size(w, h)
617+
vbox = gtk.VBox()
618+
window.add(vbox)
619+
vbox.show()
620+
621+
canvas.show()
622+
vbox.pack_start(canvas, True, True)
623+
window.show()
624+
625+
def _get_canvas(self, fig):
626+
return FigureCanvasGTK(fig)
597627

598628

599629
class NavigationToolbar(gtk.Toolbar):

0 commit comments

Comments
 (0)