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

Commitc71136e

Browse files
committed
Initial support for linestyle cycling on plot()
Added nominal tests for color and linestyle cycles
1 parent20425e2 commitc71136e

File tree

12 files changed

+762
-3
lines changed

12 files changed

+762
-3
lines changed

‎lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ def tk_window_focus():
14421442
'matplotlib.tests.test_triangulation',
14431443
'mpl_toolkits.tests.test_mplot3d',
14441444
'matplotlib.tests.test_widgets',
1445+
'matplotlib.tests.test_cycles',
14451446
]
14461447

14471448

‎lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,9 @@ def plot(self, *args, **kwargs):
12711271
12721272
By default, each line is assigned a different color specified by a
12731273
'color cycle'. To change this behavior, you can edit the
1274-
axes.color_cycle rcParam.
1274+
axes.color_cycle rcParam. Similarly, the default linestyle is
1275+
also specified by a 'linestyle cycle'. Edit the axes.linestyle_cycle
1276+
rcParam to specify a non-trivial cycle.
12751277
12761278
The following format string characters are accepted to control
12771279
the line style or marker:

‎lib/matplotlib/axes/_base.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def __init__(self, axes, command='plot'):
140140
self.axes=axes
141141
self.command=command
142142
self.set_color_cycle()
143+
self.set_linestyle_cycle()
143144

144145
def__getstate__(self):
145146
# note: it is not possible to pickle a itertools.cycle instance
@@ -148,12 +149,18 @@ def __getstate__(self):
148149
def__setstate__(self,state):
149150
self.__dict__=state.copy()
150151
self.set_color_cycle()
152+
self.set_linestyle_cycle()
151153

152154
defset_color_cycle(self,clist=None):
153155
ifclistisNone:
154156
clist=rcParams['axes.color_cycle']
155157
self.color_cycle=itertools.cycle(clist)
156158

159+
defset_linestyle_cycle(self,clist=None):
160+
ifclistisNone:
161+
clist=rcParams['axes.linestyle_cycle']
162+
self.linestyle_cycle=itertools.cycle(clist)
163+
157164
def__call__(self,*args,**kwargs):
158165

159166
ifself.axes.xaxisisnotNoneandself.axes.yaxisisnotNone:
@@ -236,6 +243,8 @@ def _makeline(self, x, y, kw, kwargs):
236243
kw['color']=six.next(self.color_cycle)
237244
# (can't use setdefault because it always evaluates
238245
# its second argument)
246+
if'linestyle'notinkwand'linestyle'notinkwargs:
247+
kw['linestyle']=six.next(self.linestyle_cycle)
239248
seg=mlines.Line2D(x,y,
240249
axes=self.axes,
241250
**kw
@@ -955,6 +964,14 @@ def set_color_cycle(self, clist):
955964
self._get_lines.set_color_cycle(clist)
956965
self._get_patches_for_fill.set_color_cycle(clist)
957966

967+
defset_linestyle_cycle(self,clist):
968+
"""
969+
Set the linestyle cycle for any future plot commands on this Axes.
970+
971+
*clist* is a list of mpl linestyle specifiers.
972+
"""
973+
self._get_lines.set_linestyle_cycle(clist)
974+
958975
defishold(self):
959976
"""return the HOLD status of the axes"""
960977
returnself._hold

‎lib/matplotlib/rcsetup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ def __call__(self, s):
612612
'axes.color_cycle': [['b','g','r','c','m','y','k'],
613613
validate_colorlist],# cycle of plot
614614
# line colors
615+
'axes.linestyle_cycle': [['-'],
616+
validate_stringlist],# cycle of plot
617+
# line styles
615618
'axes.xmargin': [0,ValidateInterval(0,1,
616619
closedmin=True,
617620
closedmax=True)],# margin added to xaxis
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp