Skip to content

Commit ba2e406

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents abfc42a + 66835a3 commit ba2e406

19 files changed

+820
-89
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Split `matplotlib.cbook.ls_mapper` in two
2+
`````````````````````````````````````````
3+
4+
The `matplotlib.cbook.ls_mapper` dictionary is split into two now to
5+
distinguish between qualified linestyle used by backends and
6+
unqualified ones. `ls_mapper` now maps from the short symbols
7+
(e.g. `"--"`) to qualified names (`"solid"`). The new ls_mapper_r is
8+
the reversed mapping.
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Removed `lod` from Artist
2+
`````````````````````````
3+
4+
Removed the method *set_lod* and all references to
5+
the attribute *_lod* as the are not used anywhere else in the
6+
code base. It appears to be a feature stub that was never built
7+
out.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Reordered `Axes.get_children`
2+
`````````````````````````````
3+
4+
The artist order returned by `Axes.get_children` did not
5+
match the one used by `Axes.draw`. They now use the same
6+
order, as `Axes.draw` now calls `Axes.get_children`.

doc/users/whats_new/linestyles.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Mostly unified linestyles for Lines, Patches and Collections
2+
````````````````````````````````````````````````````````````
3+
4+
The handling of linestyles for Lines, Patches and Collections has been
5+
unified. Now they all support defining linestyles with short symbols,
6+
like `"--"`, as well as with full names, like `"dashed"`. Also the
7+
definition using a dash pattern (`(0., [3., 3.])`) is supported for all
8+
methods using Lines, Patches or Collections.

lib/matplotlib/artist.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def __init__(self):
8989
self.clipbox = None
9090
self._clippath = None
9191
self._clipon = True
92-
self._lod = False
9392
self._label = ''
9493
self._picker = None
9594
self._contains = None
@@ -740,17 +739,6 @@ def set_alpha(self, alpha):
740739
self._alpha = alpha
741740
self.pchanged()
742741

743-
def set_lod(self, on):
744-
"""
745-
Set Level of Detail on or off. If on, the artists may examine
746-
things like the pixel width of the axes and draw a subset of
747-
their contents accordingly
748-
749-
ACCEPTS: [True | False]
750-
"""
751-
self._lod = on
752-
self.pchanged()
753-
754742
def set_visible(self, b):
755743
"""
756744
Set the artist's visiblity.
@@ -834,7 +822,6 @@ def update_from(self, other):
834822
self.clipbox = other.clipbox
835823
self._clipon = other._clipon
836824
self._clippath = other._clippath
837-
self._lod = other._lod
838825
self._label = other._label
839826
self._sketch = other._sketch
840827
self._path_effects = other._path_effects

lib/matplotlib/axes/_base.py

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,20 +2005,16 @@ def draw(self, renderer=None, inframe=False):
20052005
else:
20062006
self.apply_aspect()
20072007

2008-
artists = []
2009-
2010-
artists.extend(self.collections)
2011-
artists.extend(self.patches)
2012-
artists.extend(self.lines)
2013-
artists.extend(self.texts)
2014-
artists.extend(self.artists)
2008+
artists = self.get_children()
2009+
artists.remove(self.patch)
20152010

20162011
# the frame draws the edges around the axes patch -- we
20172012
# decouple these so the patch can be in the background and the
20182013
# frame in the foreground. Do this before drawing the axis
20192014
# objects so that the spine has the opportunity to update them.
2020-
if self.axison and self._frameon:
2021-
artists.extend(six.itervalues(self.spines))
2015+
if not (self.axison and self._frameon):
2016+
for spine in six.itervalues(self.spines):
2017+
artists.remove(spine)
20222018

20232019
if self.axison and not inframe:
20242020
if self._axisbelow:
@@ -2027,28 +2023,29 @@ def draw(self, renderer=None, inframe=False):
20272023
else:
20282024
self.xaxis.set_zorder(2.5)
20292025
self.yaxis.set_zorder(2.5)
2030-
artists.extend([self.xaxis, self.yaxis])
2031-
if not inframe:
2032-
artists.append(self.title)
2033-
artists.append(self._left_title)
2034-
artists.append(self._right_title)
2035-
artists.extend(self.tables)
2036-
if self.legend_ is not None:
2037-
artists.append(self.legend_)
2038-
2039-
if self.figure.canvas.is_saving():
2040-
dsu = [(a.zorder, a) for a in artists]
20412026
else:
2042-
dsu = [(a.zorder, a) for a in artists
2043-
if not a.get_animated()]
2027+
artists.remove(self.xaxis)
2028+
artists.remove(self.yaxis)
2029+
2030+
if inframe:
2031+
artists.remove(self.title)
2032+
artists.remove(self._left_title)
2033+
artists.remove(self._right_title)
20442034

20452035
# add images to dsu if the backend supports compositing.
20462036
# otherwise, does the manual compositing without adding images to dsu.
20472037
if len(self.images) <= 1 or renderer.option_image_nocomposite():
2048-
dsu.extend([(im.zorder, im) for im in self.images])
20492038
_do_composite = False
20502039
else:
20512040
_do_composite = True
2041+
for im in self.images:
2042+
artists.remove(im)
2043+
2044+
if self.figure.canvas.is_saving():
2045+
dsu = [(a.zorder, a) for a in artists]
2046+
else:
2047+
dsu = [(a.zorder, a) for a in artists
2048+
if (not a.get_animated() or a in self.images)]
20522049

20532050
dsu.sort(key=itemgetter(0))
20542051

@@ -3193,22 +3190,22 @@ def set_cursor_props(self, *args):
31933190
def get_children(self):
31943191
"""return a list of child artists"""
31953192
children = []
3196-
children.append(self.xaxis)
3197-
children.append(self.yaxis)
3198-
children.extend(self.lines)
3193+
children.extend(self.collections)
31993194
children.extend(self.patches)
3195+
children.extend(self.lines)
32003196
children.extend(self.texts)
3201-
children.extend(self.tables)
32023197
children.extend(self.artists)
3203-
children.extend(self.images)
3204-
if self.legend_ is not None:
3205-
children.append(self.legend_)
3206-
children.extend(self.collections)
3198+
children.extend(six.itervalues(self.spines))
3199+
children.append(self.xaxis)
3200+
children.append(self.yaxis)
32073201
children.append(self.title)
32083202
children.append(self._left_title)
32093203
children.append(self._right_title)
3204+
children.extend(self.tables)
3205+
children.extend(self.images)
3206+
if self.legend_ is not None:
3207+
children.append(self.legend_)
32103208
children.append(self.patch)
3211-
children.extend(six.itervalues(self.spines))
32123209
return children
32133210

32143211
def contains(self, mouseevent):

lib/matplotlib/cbook.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,10 @@ def unmasked_index_ranges(mask, compressed=True):
21942194
(':', 'dotted')]
21952195

21962196
ls_mapper = dict(_linestyles)
2197-
ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles])
2197+
# The ls_mapper maps short codes for line style to their full name used
2198+
# by backends
2199+
# The reverse mapper is for mapping full names to short ones
2200+
ls_mapper_r = dict([(ls[1], ls[0]) for ls in _linestyles])
21982201

21992202

22002203
def align_iterators(func, *iterables):

lib/matplotlib/collections.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,27 +482,48 @@ def set_linestyle(self, ls):
482482
"""
483483
Set the linestyle(s) for the collection.
484484
485+
=========================== =================
486+
linestyle description
487+
=========================== =================
488+
``'-'`` or ``'solid'`` solid line
489+
``'--'`` or ``'dashed'`` dashed line
490+
``'-.'`` or ``'dash_dot'`` dash-dotted line
491+
``':'`` or ``'dotted'`` dotted line
492+
=========================== =================
493+
494+
Alternatively a dash tuple of the following form can be provided::
495+
496+
(offset, onoffseq),
497+
498+
where ``onoffseq`` is an even length tuple of on and off ink
499+
in points.
500+
485501
ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' |
486-
(offset, on-off-dash-seq) ]
502+
(offset, on-off-dash-seq) |
503+
``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` |
504+
``' '`` | ``''``]
505+
506+
Parameters
507+
----------
508+
ls : { '-', '--', '-.', ':'} and more see description
509+
The line style.
487510
"""
488511
try:
489512
dashd = backend_bases.GraphicsContextBase.dashd
490513
if cbook.is_string_like(ls):
514+
ls = cbook.ls_mapper.get(ls, ls)
491515
if ls in dashd:
492516
dashes = [dashd[ls]]
493-
elif ls in cbook.ls_mapper:
494-
dashes = [dashd[cbook.ls_mapper[ls]]]
495517
else:
496518
raise ValueError()
497519
elif cbook.iterable(ls):
498520
try:
499521
dashes = []
500522
for x in ls:
501523
if cbook.is_string_like(x):
524+
x = cbook.ls_mapper.get(x, x)
502525
if x in dashd:
503526
dashes.append(dashd[x])
504-
elif x in cbook.ls_mapper:
505-
dashes.append(dashd[cbook.ls_mapper[x]])
506527
else:
507528
raise ValueError()
508529
elif cbook.iterable(x) and len(x) == 2:
@@ -511,7 +532,7 @@ def set_linestyle(self, ls):
511532
raise ValueError()
512533
except ValueError:
513534
if len(ls) == 2:
514-
dashes = ls
535+
dashes = [ls]
515536
else:
516537
raise ValueError()
517538
else:

lib/matplotlib/lines.py

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from matplotlib import verbose
1717
from . import artist
1818
from .artist import Artist
19-
from .cbook import iterable, is_string_like, is_numlike, ls_mapper
19+
from .cbook import iterable, is_string_like, is_numlike, ls_mapper_r
2020
from .colors import colorConverter
2121
from .path import Path
2222
from .transforms import Bbox, TransformedPath, IdentityTransform
@@ -921,55 +921,80 @@ def set_linewidth(self, w):
921921
"""
922922
self._linewidth = float(w)
923923

924-
def set_linestyle(self, linestyle):
924+
def set_linestyle(self, ls):
925925
"""
926-
Set the linestyle of the line (also accepts drawstyles)
926+
Set the linestyle of the line (also accepts drawstyles,
927+
e.g., ``'steps--'``)
927928
928929
929-
================ =================
930-
linestyle description
931-
================ =================
932-
``'-'`` solid
933-
``'--'`` dashed
934-
``'-.'`` dash_dot
935-
``':'`` dotted
936-
``'None'`` draw nothing
937-
``' '`` draw nothing
938-
``''`` draw nothing
939-
================ =================
930+
=========================== =================
931+
linestyle description
932+
=========================== =================
933+
``'-'`` or ``'solid'`` solid line
934+
``'--'`` or ``'dashed'`` dashed line
935+
``'-.'`` or ``'dash_dot'`` dash-dotted line
936+
``':'`` or ``'dotted'`` dotted line
937+
``'None'`` draw nothing
938+
``' '`` draw nothing
939+
``''`` draw nothing
940+
=========================== =================
940941
941942
'steps' is equivalent to 'steps-pre' and is maintained for
942943
backward-compatibility.
943944
945+
Alternatively a dash tuple of the following form can be provided::
946+
947+
(offset, onoffseq),
948+
949+
where ``onoffseq`` is an even length tuple of on and off ink
950+
in points.
951+
952+
953+
ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' |
954+
(offset, on-off-dash-seq) |
955+
``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` |
956+
``' '`` | ``''``]
957+
944958
.. seealso::
945959
946960
:meth:`set_drawstyle`
947961
To set the drawing style (stepping) of the plot.
948962
949-
ACCEPTS: [``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` |
950-
``' '`` | ``''``]
951-
952-
and any drawstyle in combination with a linestyle, e.g., ``'steps--'``.
963+
Parameters
964+
----------
965+
ls : { '-', '--', '-.', ':'} and more see description
966+
The line style.
953967
"""
968+
if not is_string_like(ls):
969+
if len(ls) != 2:
970+
raise ValueError()
971+
972+
self.set_dashes(ls[1])
973+
self._linestyle = "--"
974+
return
954975

955976
for ds in self.drawStyleKeys: # long names are first in the list
956-
if linestyle.startswith(ds):
977+
if ls.startswith(ds):
957978
self.set_drawstyle(ds)
958-
if len(linestyle) > len(ds):
959-
linestyle = linestyle[len(ds):]
979+
if len(ls) > len(ds):
980+
ls = ls[len(ds):]
960981
else:
961-
linestyle = '-'
982+
ls = '-'
962983
break
963984

964-
if linestyle not in self._lineStyles:
965-
if linestyle in ls_mapper:
966-
linestyle = ls_mapper[linestyle]
967-
else:
968-
verbose.report('Unrecognized line style %s, %s' %
969-
(linestyle, type(linestyle)))
970-
if linestyle in [' ', '']:
971-
linestyle = 'None'
972-
self._linestyle = linestyle
985+
if ls in [' ', '', 'none']:
986+
ls = 'None'
987+
988+
if ls not in self._lineStyles:
989+
try:
990+
ls = ls_mapper_r[ls]
991+
except KeyError:
992+
raise ValueError(("You passed in an invalid linestyle, "
993+
"`{}`. See "
994+
"docs of Line2D.set_linestyle for "
995+
"valid values.").format(ls))
996+
997+
self._linestyle = ls
973998

974999
@docstring.dedent_interpd
9751000
def set_marker(self, marker):

0 commit comments

Comments
 (0)