8000 Simpler and stricter process_plot_format. · matplotlib/matplotlib@48a5bd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48a5bd4

Browse files
committed
Simpler and stricter process_plot_format.
See changelog entry. The default values were removed from the docstring as they are not true, and depend not trivially on rcParams and effectively on the property cycle.
1 parent d72f069 commit 48a5bd4

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Stricter `~.Axes.plot` format string parsing
2+
````````````````````````````````````````````
3+
4+
In certain cases, `~.Axes.plot` would previously accept format strings
5+
specifying more than one linestyle (e.g. ``"---."`` which specifies both
6+
``"--"`` and ``"-."``); only use one of them would be used.
7+
8+
This now raises a ValueError instead.

lib/matplotlib/axes/_base.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@
3434

3535
def _process_plot_format(fmt):
3636
"""
37-
Process a MATLAB style color/line style format string. Return a
38-
(*linestyle*, *color*) tuple as a result of the processing. Default
39-
values are ('-', 'b'). Example format strings include:
37+
Convert a MATLAB style color/line style format string to a (*linestyle*,
38+
*marker*, *color*) tuple.
39+
40+
Example format strings include:
4041
4142
* 'ko': black circles
4243
* '.b': blue dots
@@ -73,24 +74,16 @@ def _process_plot_format(fmt):
7374
except ValueError:
7475
pass # No, not just a color.
7576

76-
# handle the multi char special cases and strip them from the
77-
# string
78-
if fmt.find('--') >= 0:
79-
linestyle = '--'
80-
fmt = fmt.replace('--', '')
81-
if fmt.find('-.') >= 0:
82-
linestyle = '-.'
83-
fmt = fmt.replace('-.', '')
84-
if fmt.find(' ') >= 0:
85-
linestyle = 'None'
86-
fmt = fmt.replace(' ', '')
87-
88-
chars = [c for c in fmt]
89-
9077
i = 0
91-
while i < len(chars):
92-
c = chars[i]
93-
if c in mlines.lineStyles:
78+
while i < len(fmt):
79+
c = fmt[i]
80+
if fmt[i:i+2] in mlines.lineStyles: # First, the two-char styles.
81+
if linestyle is not None:
82+
raise ValueError(
83+
'Illegal format string "%s"; two linestyle symbols' % fmt)
84+
linestyle = fmt[i:i+2]
85+
i += 1
86+
elif c in mlines.lineStyles:
9487
if linestyle is not None:
9588
raise ValueError(
9689
'Illegal format string "%s"; two linestyle symbols' % fmt)
@@ -105,8 +98,8 @@ def _process_plot_format(fmt):
10598
raise ValueError(
10699
'Illegal format string "%s"; two color symbols' % fmt)
107100
color = c
108-
elif c == 'C' and i < len(chars) - 1:
109-
color_cycle_number = int(chars[i + 1])
101+
elif c == 'C' and i < len(fmt) - 1:
102+
color_cycle_number = int(fmt[i + 1])
110103
color = mcolors.to_rgba("C{}".format(color_cycle_number))
111104
i += 1
112105
else:
@@ -117,9 +110,9 @@ def _process_plot_format(fmt):
117110
if linestyle is None and marker is None:
118111
linestyle = rcParams['lines.linestyle']
119112
if linestyle is None:
120-
linestyle = 'None'
113+
linestyle = 'none'
121114
if marker is None:
122-
marker = 'None'
115+
marker = 'none'
123116

124117
return linestyle, marker, color
125118

0 commit comments

Comments
 (0)
0