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

Commit3bc8636

Browse files
committed
Style cleanup to pyplot.
... preliminary to more refactoring.Nearly everything is mechanical; the only subtle point is that figure()does not need to handle the figure.foo rcParams as the Figureconstructor takes care of that.
1 parent030157c commit3bc8636

File tree

1 file changed

+46
-70
lines changed

1 file changed

+46
-70
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@
6161
frommatplotlib.patchesimportPolygon,Rectangle,Circle,Arrow
6262
frommatplotlib.widgetsimportSubplotTool,Button,Slider,Widget
6363

64-
from .tickerimportTickHelper,Formatter,FixedFormatter,NullFormatter,\
65-
FuncFormatter,FormatStrFormatter,ScalarFormatter,\
66-
LogFormatter,LogFormatterExponent,LogFormatterMathtext,\
67-
Locator,IndexLocator,FixedLocator,NullLocator,\
68-
LinearLocator,LogLocator,AutoLocator,MultipleLocator,\
69-
MaxNLocator
64+
from .tickerimport (
65+
TickHelper,Formatter,FixedFormatter,NullFormatter,FuncFormatter,
66+
FormatStrFormatter,ScalarFormatter,LogFormatter,LogFormatterExponent,
67+
LogFormatterMathtext,Locator,IndexLocator,FixedLocator,NullLocator,
68+
LinearLocator,LogLocator,AutoLocator,MultipleLocator,MaxNLocator)
7069
frommatplotlib.backendsimport_get_running_interactive_framework
7170

7271
_log=logging.getLogger(__name__)
@@ -492,88 +491,65 @@ def figure(num=None, # autoincrement if None, else integer from 1-N
492491
in the matplotlibrc file.
493492
"""
494493

495-
iffigsizeisNone:
496-
figsize=rcParams['figure.figsize']
497-
ifdpiisNone:
498-
dpi=rcParams['figure.dpi']
499-
iffacecolorisNone:
500-
facecolor=rcParams['figure.facecolor']
501-
ifedgecolorisNone:
502-
edgecolor=rcParams['figure.edgecolor']
503-
504494
allnums=get_fignums()
505495
next_num=max(allnums)+1ifallnumselse1
506-
figLabel=''
496+
fig_label=''
507497
ifnumisNone:
508498
num=next_num
509499
elifisinstance(num,str):
510-
figLabel=num
511-
allLabels=get_figlabels()
512-
iffigLabelnotinallLabels:
513-
iffigLabel=='all':
500+
fig_label=num
501+
all_labels=get_figlabels()
502+
iffig_labelnotinall_labels:
503+
iffig_label=='all':
514504
cbook._warn_external(
515-
"close('all') closes all existing figures")
505+
"close('all') closes all existing figures.")
516506
num=next_num
517507
else:
518-
inum=allLabels.index(figLabel)
508+
inum=all_labels.index(fig_label)
519509
num=allnums[inum]
520510
else:
521511
num=int(num)# crude validation of num argument
522512

523-
figManager=_pylab_helpers.Gcf.get_fig_manager(num)
524-
iffigManagerisNone:
513+
manager=_pylab_helpers.Gcf.get_fig_manager(num)
514+
ifmanagerisNone:
525515
max_open_warning=rcParams['figure.max_open_warning']
526-
527516
iflen(allnums)>=max_open_warning>=1:
528517
cbook._warn_external(
529-
"More than %d figures have been opened. Figures "
530-
"created through the pyplot interface "
531-
"(`matplotlib.pyplot.figure`) are retained until "
532-
"explicitly closed and may consume too much memory. "
533-
"(To control this warning, see the rcParam "
534-
"`figure.max_open_warning`)."%
535-
max_open_warning,RuntimeWarning)
536-
518+
f"More than{max_open_warning} figures have been opened. "
519+
f"Figures created through the pyplot interface "
520+
f"(`matplotlib.pyplot.figure`) are retained until explicitly "
521+
f"closed and may consume too much memory. (To control this "
522+
f"warning, see the rcParam `figure.max_open_warning`).",
523+
RuntimeWarning)
537524
ifget_backend().lower()=='ps':
538525
dpi=72
539-
540-
figManager=new_figure_manager(num,figsize=figsize,
541-
dpi=dpi,
542-
facecolor=facecolor,
543-
edgecolor=edgecolor,
544-
frameon=frameon,
545-
FigureClass=FigureClass,
546-
**kwargs)
547-
548-
iffigLabel:
549-
figManager.set_window_title(figLabel)
550-
figManager.canvas.figure.set_label(figLabel)
551-
526+
manager=new_figure_manager(
527+
num,figsize=figsize,dpi=dpi,
528+
facecolor=facecolor,edgecolor=edgecolor,frameon=frameon,
529+
FigureClass=FigureClass,**kwargs)
530+
iffig_label:
531+
manager.set_window_title(fig_label)
532+
manager.canvas.figure.set_label(fig_label)
552533
# make this figure current on button press event
553-
defmake_active(event):
554-
_pylab_helpers.Gcf.set_active(figManager)
555-
556-
cid=figManager.canvas.mpl_connect('button_press_event',make_active)
557-
figManager._cidgcf=cid
558-
559-
_pylab_helpers.Gcf.set_active(figManager)
560-
fig=figManager.canvas.figure
534+
manager._cidgcf=manager.canvas.mpl_connect(
535+
'button_press_event',
536+
lambdaevent:_pylab_helpers.Gcf.set_active(manager))
537+
_pylab_helpers.Gcf.set_active(manager)
538+
fig=manager.canvas.figure
561539
fig.number=num
562-
563540
# make sure backends (inline) that we don't ship that expect this
564541
# to be called in plotting commands to make the figure call show
565542
# still work. There is probably a better way to do this in the
566543
# FigureManager base class.
567544
ifmatplotlib.is_interactive():
568545
draw_if_interactive()
569-
570546
if_INSTALL_FIG_OBSERVER:
571547
fig.stale_callback=_auto_draw_if_interactive
572548

573549
ifclear:
574-
figManager.canvas.figure.clear()
550+
manager.canvas.figure.clear()
575551

576-
returnfigManager.canvas.figure
552+
returnmanager.canvas.figure
577553

578554

579555
def_auto_draw_if_interactive(fig,val):
@@ -597,9 +573,9 @@ def gcf():
597573
If no current figure exists, a new one is created using
598574
`~.pyplot.figure()`.
599575
"""
600-
figManager=_pylab_helpers.Gcf.get_active()
601-
iffigManagerisnotNone:
602-
returnfigManager.canvas.figure
576+
manager=_pylab_helpers.Gcf.get_active()
577+
ifmanagerisnotNone:
578+
returnmanager.canvas.figure
603579
else:
604580
returnfigure()
605581

@@ -616,9 +592,9 @@ def get_fignums():
616592

617593
defget_figlabels():
618594
"""Return a list of existing figure labels."""
619-
figManagers=_pylab_helpers.Gcf.get_all_fig_managers()
620-
figManagers.sort(key=lambdam:m.num)
621-
return [m.canvas.figure.get_label()forminfigManagers]
595+
managers=_pylab_helpers.Gcf.get_all_fig_managers()
596+
managers.sort(key=lambdam:m.num)
597+
return [m.canvas.figure.get_label()forminmanagers]
622598

623599

624600
defget_current_fig_manager():
@@ -665,11 +641,11 @@ def close(fig=None):
665641
666642
"""
667643
iffigisNone:
668-
figManager=_pylab_helpers.Gcf.get_active()
669-
iffigManagerisNone:
644+
manager=_pylab_helpers.Gcf.get_active()
645+
ifmanagerisNone:
670646
return
671647
else:
672-
_pylab_helpers.Gcf.destroy(figManager.num)
648+
_pylab_helpers.Gcf.destroy(manager.num)
673649
eliffig=='all':
674650
_pylab_helpers.Gcf.destroy_all()
675651
elifisinstance(fig,int):
@@ -679,9 +655,9 @@ def close(fig=None):
679655
# can use its integer representation
680656
_pylab_helpers.Gcf.destroy(fig.int)
681657
elifisinstance(fig,str):
682-
allLabels=get_figlabels()
683-
iffiginallLabels:
684-
num=get_fignums()[allLabels.index(fig)]
658+
all_labels=get_figlabels()
659+
iffiginall_labels:
660+
num=get_fignums()[all_labels.index(fig)]
685661
_pylab_helpers.Gcf.destroy(num)
686662
elifisinstance(fig,Figure):
687663
_pylab_helpers.Gcf.destroy_fig(fig)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp