Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit770d0a0

Browse files
committed
fixed a close(fig) bug
svn path=/trunk/matplotlib/; revision=909
1 parentc17e217 commit770d0a0

File tree

7 files changed

+78
-39
lines changed

7 files changed

+78
-39
lines changed

‎API_CHANGES

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ API CHANGES in matplotlib-0.72
33
Line2D, Text, and Patch copy_properties renamed update_from and
44
moved into artist base class
55

6-
LineCollecitons.color renamed to LineCollections.set_color for
7-
consistency with set/get introspection mechanism,
6+
LineCollecitons.color renamed to LineCollections.set_color for
7+
consistency with set/get introspection mechanism,
88

9+
pylab figure now defaults to num=None, which creates a new figure
10+
with a guaranteed unique number
911

1012
API CHANGES in matplotlib-0.71
1113

‎CHANGELOG

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

33
2005-02-01 Added Fernando's figure num patch, including experemental
44
support for pylab backend switching, LineCOllection.color
5-
warns - JDH
5+
warns, savefig now a figure method, fixed a close(fig) bug
6+
- JDH
67

78
2005-01-31 updated datalim in contour - JDH
89

@@ -28,7 +29,7 @@ New entries should be added at the top
2829
2005-01-24 Fixed a mathtext parser bug that prevented font changes in
2930
sub/superscripts - JDH
3031

31-
2005-01-24 Fixed contourwto work w/ interactive changes in colormaps,
32+
2005-01-24 Fixed contourto work w/ interactive changes in colormaps,
3233
clim, etc - JDH
3334

3435
===============================================================

‎examples/agg_oo.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
"""
3+
A pure OO (look Ma, no pylab!) example using the agg backend
4+
"""
5+
frommatplotlib.backends.backend_aggimportFigureCanvasAggasFigureCanvas
6+
frommatplotlib.figureimportFigure
7+
8+
fig=Figure()
9+
canvas=FigureCanvas(fig)
10+
ax=fig.add_subplot(111)
11+
ax.plot([1,2,3])
12+
ax.set_title('hi mom')
13+
ax.grid(True)
14+
ax.set_xlabel('time')
15+
ax.set_ylabel('volts')
16+
canvas.print_figure('test')

‎lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ class FigureCanvasBase:
662662
)
663663

664664
def__init__(self,figure):
665+
figure.set_canvas(self)
665666
self.figure=figure
666667
self.cid=0
667668
# a dictionary from event name to a dictionary that maps cid->func

‎lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ def destroy(self, *args):
286286
ifself.windowisnotNone:
287287
#print 'calling window destroy'
288288
self.window.destroy()
289+
pass
289290
self.window=None
290291

291292
classAxisMenu:

‎lib/matplotlib/figure.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ def __init__(self,
5959
self._set_artist_props(self.figurePatch)
6060

6161
self._hold=rcParams['axes.hold']
62+
self.canvas=None
6263
self.clf()
6364

65+
defset_canvas(self,canvas):
66+
'set the canvas the contains the figure'
67+
self.canvas=canvas
6468

6569
defhold(self,b=None):
6670
"""
@@ -427,3 +431,26 @@ def add_axobserver(self, func):
427431
'whenever the axes state change, func(self) will be called'
428432
self._axobservers.append(func)
429433

434+
435+
defsavefig(self,*args,**kwargs):
436+
"""
437+
SAVEFIG(fname, dpi=150, facecolor='w', edgecolor='w',
438+
orientation='portrait'):
439+
440+
Save the current figure to filename fname. dpi is the resolution
441+
in dots per inch.
442+
443+
Output file types currently supported are jpeg and png and will be
444+
deduced by the extension to fname
445+
446+
facecolor and edgecolor are the colors os the figure rectangle
447+
448+
orientation is either 'landscape' or 'portrait' - not supported on
449+
all backends; currently only on postscript output."""
450+
451+
forkeyin ('dpi','facecolor','edgecolor'):
452+
ifnotkwargs.has_key(key):
453+
kwargs[key]=rcParams['savefig.%s'%key]
454+
455+
self.canvas.print_figure(*args,**kwargs)
456+

‎lib/matplotlib/pylab.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,10 @@ def close(*args):
610610
_pylab_helpers.Gcf.destroy(arg)
611611
elifisinstance(arg,Figure):
612612
formanagerin_pylab_helpers.Gcf.get_all_fig_managers():
613-
ifmanager.figure==arg:
613+
ifmanager.canvas.figure==arg:
614614
_pylab_helpers.Gcf.destroy(manager.num)
615615
else:
616-
error_msg('Unrecognized argument type to close')
616+
error_msg('Unrecognized argument type%sto close'%type(arg))
617617
else:
618618
error_msg('close takes 0 or 1 arguments')
619619

@@ -757,6 +757,15 @@ def figlegend(handles, labels, loc, **kwargs):
757757
l=gcf().legend(handles,labels,loc,**kwargs)
758758
draw_if_interactive()
759759
returnl
760+
761+
defsavefig(*args,**kwargs):
762+
try:ret=gcf().savefig(*args,**kwargs)
763+
exceptRuntimeError,msg:
764+
msg=raise_msg_to_str(msg)
765+
error_msg(msg)
766+
raiseRuntimeError(msg)
767+
else:returnret
768+
savefig.__doc__=Figure.savefig.__doc__
760769

761770

762771
deffigure(num=None,# autoincrement if None, else integer from 1-N
@@ -767,23 +776,27 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
767776
frameon=True,
768777
):
769778
"""
770-
figure(num = 1, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')
779+
figure(num = None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')
780+
771781
782+
Create a new figure and return a handle to it. If num=None, the
783+
figure number will be incremented and a new figure will be
784+
created.
772785
773-
Create a new figure and return a handle to it
774786
775-
If figure(num) already exists, make it active and return the
776-
handle to it.
787+
If num is an integer, and figure(num) already exists, make it
788+
active and return the handle to it. If figure(num) does not exist
789+
it will be created. Numbering starts at 1, matlab style
777790
778791
figure(1)
779792
780-
If num=None, the figure number will be incremented and a new
781-
figure will be created.
782-
783-
figsize - width in height x inches; defaults to rc figure.figsize
784-
dpi - resolution; defaults to rc figure.dpi
785-
facecolor - the background color; defaults to rc figure.facecolor
786-
edgecolor - the border color; defaults to rc figure.edgecolor
793+
794+
kwargs:
795+
796+
figsize - width in height x inches; defaults to rc figure.figsize
797+
dpi - resolution; defaults to rc figure.dpi
798+
facecolor - the background color; defaults to rc figure.facecolor
799+
edgecolor - the border color; defaults to rc figure.edgecolor
787800
788801
rcParams gives the default values from the .matplotlibrc file
789802
@@ -1019,28 +1032,6 @@ def save(fname, X, fmt='%1.4f'):
10191032
iforigShapeisnotNone:
10201033
X.shape=origShape
10211034

1022-
defsavefig(*args,**kwargs):
1023-
"""
1024-
SAVEFIG(fname, dpi=150, facecolor='w', edgecolor='w',
1025-
orientation='portrait'):
1026-
1027-
Save the current figure to filename fname. dpi is the resolution
1028-
in dots per inch.
1029-
1030-
Output file types currently supported are jpeg and png and will be
1031-
deduced by the extension to fname
1032-
1033-
facecolor and edgecolor are the colors os the figure rectangle
1034-
1035-
orientation is either 'landscape' or 'portrait' - not supported on
1036-
all backends; currently only on postscript output."""
1037-
1038-
forkeyin ('dpi','facecolor','edgecolor'):
1039-
ifnotkwargs.has_key(key):
1040-
kwargs[key]=rcParams['savefig.%s'%key]
1041-
1042-
manager=get_current_fig_manager()
1043-
manager.canvas.print_figure(*args,**kwargs)
10441035

10451036
class_ObjectInspector:
10461037

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp