diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 456b86ff4eae..51eaf0da3dff 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -1446,6 +1446,7 @@ def tk_window_focus(): 'matplotlib.tests.test_transforms', 'matplotlib.tests.test_triangulation', 'mpl_toolkits.tests.test_mplot3d', + 'matplotlib.tests.test_fmt' ] diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 91dfc0478ae4..6daa3cc7ea3f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -63,7 +63,8 @@ def _process_plot_format(fmt): # Is fmt just a colorspec? try: - color = mcolors.colorConverter.to_rgb(fmt) + mcolors.colorConverter.to_rgb(fmt) + color = fmt # We need to differentiate grayscale '1.0' from tri_down marker '1' try: @@ -80,27 +81,23 @@ def _process_plot_format(fmt): except ValueError: pass # No, not just a color. - # handle the multi char special cases and strip them from the - # string - if fmt.find('--') >= 0: - linestyle = '--' - fmt = fmt.replace('--', '') - if fmt.find('-.') >= 0: - linestyle = '-.' - fmt = fmt.replace('-.', '') - if fmt.find(' ') >= 0: - linestyle = 'None' - fmt = fmt.replace(' ', '') + for ls in sorted(mlines.lineStyles, key=len, reverse=True): + if fmt.find(ls) >= 0: + linestyle = ls + fmt = fmt.replace(ls, '') + break + + # Check for double linestyle definition + if linestyle: + for ls in sorted(mlines.lineStyles, key=len): + if fmt.find(ls) >= 0: + raise ValueError( + 'Illegal format string "%s"; two linestyle symbols' % fmt) chars = [c for c in fmt] for c in chars: - if c in mlines.lineStyles: - if linestyle is not None: - raise ValueError( - 'Illegal format string "%s"; two linestyle symbols' % fmt) - linestyle = c - elif c in mlines.lineMarkers: + if c in mlines.lineMarkers: if marker is not None: raise ValueError( 'Illegal format string "%s"; two marker symbols' % fmt) @@ -114,11 +111,9 @@ def _process_plot_format(fmt): raise ValueError( 'Unrecognized character %c in format string' % c) - if linestyle is None and marker is None: - linestyle = rcParams['lines.linestyle'] - if linestyle is None: + if linestyle is None and marker is not None: linestyle = 'None' - if marker is None: + if marker is None and linestyle is not None: marker = 'None' return linestyle, marker, color diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 538e0d19d207..b6bfa4afb3c9 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -2108,7 +2108,6 @@ def unmasked_index_ranges(mask, compressed=True): (':', 'dotted')] ls_mapper = dict(_linestyles) -ls_mapper.update([(ls[1], ls[0]) for ls in _linestyles]) def align_iterators(func, *iterables): diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 506583404d9e..ccb41c776a0f 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -463,16 +463,27 @@ def set_linestyle(self, ls): """ Set the linestyle(s) for the collection. - ACCEPTS: ['solid' | 'dashed', 'dashdot', 'dotted' | - (offset, on-off-dash-seq) ] + + Parameters + ---------- + ls : { '-', '--', '-.', ':'} and more see description + The line style. The written out linestyles + 'solid', 'dashed', 'dashdot' and 'dotted' and drawstyle in + combination with a linestyle, e.g., ``'steps--'`` are also allowed. + + Alternatively a dash tuple of the following form can be provided:: + + (offset, onoffseq), + + where ``onoffseq`` is an even length tuple of on and off ink + in points. """ try: dashd = backend_bases.GraphicsContextBase.dashd if cbook.is_string_like(ls): + ls = cbook.ls_mapper.get(ls, ls) if ls in dashd: dashes = [dashd[ls]] - elif ls in cbook.ls_mapper: - dashes = [dashd[cbook.ls_mapper[ls]]] else: raise ValueError() elif cbook.iterable(ls): @@ -480,10 +491,9 @@ def set_linestyle(self, ls): dashes = [] for x in ls: if cbook.is_string_like(x): + x = cbook.ls_mapper.get(x, x) if x in dashd: dashes.append(dashd[x]) - elif x in cbook.ls_mapper: - dashes.append(dashd[cbook.ls_mapper[x]]) else: raise ValueError() elif cbook.iterable(x) and len(x) == 2: @@ -492,7 +502,7 @@ def set_linestyle(self, ls): raise ValueError() except ValueError: if len(ls) == 2: - dashes = ls + dashes = [ls] else: raise ValueError() else: diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 09fc968b04d1..6d002d30f002 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -25,6 +25,8 @@ from .artist import allow_rasterization from matplotlib import docstring from matplotlib.markers import MarkerStyle +import matplotlib.backend_bases + # Imported here for backward compatibility, even though they don't # really belong. from matplotlib.markers import TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN @@ -194,15 +196,9 @@ class Line2D(Artist): """ - lineStyles = _lineStyles = { # hidden names deprecated - '-': '_draw_solid', - '--': '_draw_dashed', - '-.': '_draw_dash_dot', - ':': '_draw_dotted', - 'None': '_draw_nothing', - ' ': '_draw_nothing', - '': '_draw_nothing', - } + lineStyles = _lineStyles = [ # hidden names deprecated + '-', '--', '-.', ':' # , 'None', ' ', #'' + ] _drawStyles_l = { 'default': '_draw_lines', @@ -328,7 +324,6 @@ def __init__(self, xdata, ydata, self.set_markevery(markevery) self.set_antialiased(antialiased) self.set_markersize(markersize) - self._dashSeq = None self.set_markerfacecolor(markerfacecolor) self.set_markerfacecoloralt(markerfacecoloralt) @@ -408,7 +403,7 @@ def contains(self, mouseevent): olderrflags = np.seterr(all='ignore') try: # Check for collision - if self._linestyle in ['None', None]: + if not self._linestyle: # If no line, return the nearby point(s) d = (xt - mouseevent.x) ** 2 + (yt - mouseevent.y) ** 2 ind, = np.nonzero(np.less_equal(d, pixels ** 2)) @@ -702,11 +697,10 @@ def draw(self, renderer): if self.get_sketch_params() is not None: gc.set_sketch_params(*self.get_sketch_params()) - funcname = self._lineStyles.get(self._linestyle, '_draw_nothing') - if funcname != '_draw_nothing': + linestyle = self._linestyle + if linestyle: tpath, affine = transf_path.get_transformed_path_and_affine() if len(tpath.vertices): - self._lineFunc = getattr(self, funcname) funcname = self.drawStyles.get(self._drawstyle, '_draw_lines') drawFunc = getattr(self, funcname) drawFunc(renderer, gc, tpath, affine.frozen()) @@ -921,17 +915,17 @@ def set_linestyle(self, linestyle): Set the linestyle of the line (also accepts drawstyles) - ================ ================= - linestyle description - ================ ================= - ``'-'`` solid - ``'--'`` dashed - ``'-.'`` dash_dot - ``':'`` dotted - ``'None'`` draw nothing - ``' '`` draw nothing - ``''`` draw nothing - ================ ================= + =========================== ================= + linestyle description + =========================== ================= + ``'-'`` or ``'solid'`` solid line + ``'--'`` or ``'dashed'`` dashed line + ``'-.'`` or ``'dash_dot'`` dash-dotted line + ``':'`` or ``'dotted'`` dotted line + ``'None'`` draw nothing + ``' '`` draw nothing + ``''`` draw nothing + =========================== ================= 'steps' is equivalent to 'steps-pre' and is maintained for backward-compatibility. @@ -941,11 +935,26 @@ def set_linestyle(self, linestyle): :meth:`set_drawstyle` To set the drawing style (stepping) of the plot. - ACCEPTS: [``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | - ``' '`` | ``''``] + Parameters + ---------- + ls : { '-', '--', '-.', ':'} and more see description + The line style. The written out linestyles + 'solid', 'dashed', 'dashdot' and 'dotted' and drawstyle in + combination with a linestyle, e.g., ``'steps--'`` are also allowed. + + Alternatively a dash tuple of the following form can be provided:: + + (offset, onoffseq), - and any drawstyle in combination with a linestyle, e.g., ``'steps--'``. + where ``onoffseq`` is an even length tuple of on and off ink + in points. """ + if not is_string_like(linestyle): + if len(linestyle) != 2: + raise ValueError() + + self._linestyle = linestyle + return for ds in self.drawStyleKeys: # long names are first in the list if linestyle.startswith(ds): @@ -956,14 +965,19 @@ def set_linestyle(self, linestyle): linestyle = '-' break - if linestyle not in self._lineStyles: - if linestyle in ls_mapper: - linestyle = ls_mapper[linestyle] - else: + linestyle = ls_mapper.get(linestyle, linestyle) + # TODO: check if in dashd of backend? + #else: + # verbose.report('Unrecognized line style %s, %s' % + # (linestyle, type(linestyle))) + if linestyle in [' ', 'None', 'none', '']: + linestyle = '' + else: + dashd = matplotlib.backend_bases.GraphicsContextBase.dashd + if linestyle not in dashd: verbose.report('Unrecognized line style %s, %s' % (linestyle, type(linestyle))) - if linestyle in [' ', '']: - linestyle = 'None' + linestyle = '' self._linestyle = linestyle @docstring.dedent_interpd @@ -1060,11 +1074,11 @@ def set_dashes(self, seq): if seq == (None, None) or len(seq) == 0: self.set_linestyle('-') else: - self.set_linestyle('--') - self._dashSeq = seq # TODO: offset ignored for now + self._linestyle = (0, seq) # TODO: offset ignored for now def _draw_lines(self, renderer, gc, path, trans): - self._lineFunc(renderer, gc, path, trans) + gc.set_linestyle(self._linestyle) + renderer.draw_path(gc, path, trans) def _draw_steps_pre(self, renderer, gc, path, trans): vertices = self._xy @@ -1075,7 +1089,7 @@ def _draw_steps_pre(self, renderer, gc, path, trans): path = Path(steps) path = path.transformed(self.get_transform()) - self._lineFunc(renderer, gc, path, IdentityTransform()) + self._draw_lines(renderer, gc, path, IdentityTransform()) def _draw_steps_post(self, renderer, gc, path, trans): vertices = self._xy @@ -1086,7 +1100,7 @@ def _draw_steps_post(self, renderer, gc, path, trans): path = Path(steps) path = path.transformed(self.get_transform()) - self._lineFunc(renderer, gc, path, IdentityTransform()) + self._draw_lines(renderer, gc, path, IdentityTransform()) def _draw_steps_mid(self, renderer, gc, path, trans): vertices = self._xy @@ -1100,26 +1114,7 @@ def _draw_steps_mid(self, renderer, gc, path, trans): path = Path(steps) path = path.transformed(self.get_transform()) - self._lineFunc(renderer, gc, path, IdentityTransform()) - - def _draw_solid(self, renderer, gc, path, trans): - gc.set_linestyle('solid') - renderer.draw_path(gc, path, trans) - - def _draw_dashed(self, renderer, gc, path, trans): - gc.set_linestyle('dashed') - if self._dashSeq is not None: - gc.set_dashes(0, self._dashSeq) - - renderer.draw_path(gc, path, trans) - - def _draw_dash_dot(self, renderer, gc, path, trans): - gc.set_linestyle('dashdot') - renderer.draw_path(gc, path, trans) - - def _draw_dotted(self, renderer, gc, path, trans): - gc.set_linestyle('dotted') - renderer.draw_path(gc, path, trans) + self._draw_lines(renderer, gc, path, IdentityTransform()) def update_from(self, other): """copy properties from other to self""" @@ -1132,13 +1127,11 @@ def update_from(self, other): self._markerfacecoloralt = other._markerfacecoloralt self._markeredgecolor = other._markeredgecolor self._markeredgewidth = other._markeredgewidth - self._dashSeq = other._dashSeq self._dashcapstyle = other._dashcapstyle self._dashjoinstyle = other._dashjoinstyle self._solidcapstyle = other._solidcapstyle self._solidjoinstyle = other._solidjoinstyle - self._linestyle = other._linestyle self._marker = MarkerStyle(other._marker.get_marker(), other._marker.get_fillstyle()) self._drawstyle = other._drawstyle @@ -1309,7 +1302,8 @@ def get_solid_capstyle(self): def is_dashed(self): 'return True if line is dashstyle' - return self._linestyle in ('--', '-.', ':') + return (self._linestyle in ('dashed', 'dashdot', 'dotted') or + not is_string_like(self._linestyle)) class VertexSelector(object): diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 339f111c2a2f..7f48183f2a57 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -339,10 +339,24 @@ def set_linestyle(self, ls): """ Set the patch linestyle - ACCEPTS: ['solid' | 'dashed' | 'dashdot' | 'dotted'] + Parameters + ---------- + ls : { '-', '--', '-.', ':'} and more see description + The line style. The written out linestyles + 'solid', 'dashed', 'dashdot' and 'dotted' and drawstyle in + combination with a linestyle, e.g., ``'steps--'`` are also allowed. + + Alternatively a dash tuple of the following form can be provided:: + + (offset, onoffseq), + + where ``onoffseq`` is an even length tuple of on and off ink + in points. """ if ls is None: ls = "solid" + + ls = cbook.ls_mapper.get(ls, ls) self._linestyle = ls def set_ls(self, ls): diff --git a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf new file mode 100644 index 000000000000..55f48e230c9b Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.png b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.png new file mode 100644 index 000000000000..e748ee7e6928 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg new file mode 100644 index 000000000000..f81cb6ca0ff5 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_collections/EventCollection_plot__set_ls_dash.svg @@ -0,0 +1,697 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.pdf b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.pdf new file mode 100644 index 000000000000..ca440b3adecb Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.png b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.png new file mode 100644 index 000000000000..3d1e7195797c Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.svg b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.svg new file mode 100644 index 000000000000..d693b936214a --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_lines/line_dashes.svg @@ -0,0 +1,335 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index e4e709ffc0f0..4735ce1c339c 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -323,6 +323,18 @@ def test__EventCollection__set_linestyle(): splt.set_title('EventCollection: set_linestyle') +@image_comparison(baseline_images=['EventCollection_plot__set_ls_dash']) +def test__EventCollection__set_linestyle_single_dash(): + ''' + check to make sure set_linestyle accepts a single dash pattern + ''' + splt, coll, _ = generate_EventCollection_plot() + new_linestyle = (0, (6., 6.)) + coll.set_linestyle(new_linestyle) + assert_equal(coll.get_linestyle(), [(0, (6.0, 6.0))]) + splt.set_title('EventCollection: set_linestyle') + + @image_comparison(baseline_images=['EventCollection_plot__set_linewidth']) def test__EventCollection__set_linewidth(): ''' @@ -496,7 +508,7 @@ def test_polycollection_close(): vertsQuad * len(zpos), linewidth=0.25) poly.set_alpha(0.7) - ## need to have a z-value for *each* polygon = element! + # need to have a z-value for *each* polygon = element! zs = [] cs = [] for z, c in zip(zpos, colors): @@ -507,7 +519,7 @@ def test_polycollection_close(): ax.add_collection3d(poly, zs=zs, zdir='y') - ## axis limit settings: + # axis limit settings: ax.set_xlim3d(0, 4) ax.set_zlim3d(0, 3) ax.set_ylim3d(0, 4) diff --git a/lib/matplotlib/tests/test_fmt.py b/lib/matplotlib/tests/test_fmt.py new file mode 100644 index 000000000000..7fc3fdb5dde9 --- /dev/null +++ b/lib/matplotlib/tests/test_fmt.py @@ -0,0 +1,76 @@ +from __future__ import (absolute_import, division, print_function, + unicode_literals) +from matplotlib.testing.decorators import cleanup +import six + + +from nose.tools import assert_equal, assert_raises + +from matplotlib.axes._axes import _process_plot_format + + +@cleanup +def _fmt_parsing_helper(fmt, ref): + assert_equal(ref, _process_plot_format(fmt)) + + +@cleanup +def _fmt_parsing_invalid_helper(fmt): + assert_raises(ValueError, _process_plot_format, fmt) + + +def test_fmt_parsing(): + test_cases = (('-', ('-', 'None', None)), + ('--', ('--', 'None', None)), + ('-.', ('-.', 'None', None)), + (':', (':', 'None', None)), + ('-g', ('-', 'None', 'g')), + ('--r', ('--', 'None', 'r')), + ('-.k', ('-.', 'None', 'k')), + (':b', (':', 'None', 'b')), + ('-o', ('-', 'o', None)), + ('--,', ('--', ',', None)), + ('-..', ('-.', '.', None)), + ('v:', (':', 'v', None)), + ('-g^', ('-', '^', 'g')), + ('--r<', ('--', '<', 'r')), + (':>g', (':', '>', 'g')), + ('.-.k', ('-.', '.', 'k')), + ('-c', ('-', 'None', 'c')), + ('-1m', ('-', '1', 'm')), + ('-y2', ('-', '2', 'y')), + ('w-3', ('-', '3', 'w')), + ('--.', ('--', '.', None)), + ('-4k', ('-', '4', 'k')), + ('sk', ('None', 's', 'k')), + ('r', (None, None, 'r')), + ('1.0', (None, None, '1.0')), + ('0.8', (None, None, '0.8')), + ('p', ('None', 'p', None)), + ('*--', ('--', '*', None)), + ('kh:', (':', 'h', 'k')), + ('H-r', ('-', 'H', 'r')), + ('--+g', ('--', '+', 'g')), + (':xb', (':', 'x', 'b')), + ('cD-.', ('-.', 'D', 'c')), + ('m--d', ('--', 'd', 'm')), + (':y|', (':', '|', 'y')), + ('w_-', ('-', '_', 'w')) + ) + + for fmt, target in test_cases: + yield _fmt_parsing_helper, fmt, target + + +def test_fmt_parsing_fail(): + test_strings = ('bb-', + 'xog', + '---.', + ':-', + '12c', + '--ph', + ',u', + ',1.0', + '.0.8') + for fmt in test_strings: + yield _fmt_parsing_invalid_helper, fmt diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index 55aa360af737..80cc260935ad 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -71,6 +71,14 @@ def test_set_line_coll_dash(): assert True +@image_comparison(baseline_images=['line_dashes'], remove_text=True) +def test_line_dashes(): + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1) + + ax.plot(range(10), linestyle=(0, (3, 3)), lw=5) + + @cleanup def test_line_colors(): fig = plt.figure() @@ -84,6 +92,18 @@ def test_line_colors(): assert True +@cleanup +def test_linestyle_accents(): + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1) + for ls in ["-", "solid", "--", "dashed", + "-.", "dashdot", ":", "dotted"]: + ax.plot(range(10), linestyle=ls) + + fig.canvas.draw() + assert True + + @image_comparison(baseline_images=['line_collection_dashes'], remove_text=True) def test_set_line_coll_dash_image(): fig = plt.figure() diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 1c8549d29255..44856642b282 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -13,7 +13,7 @@ from matplotlib.patches import Polygon from matplotlib.patches import Rectangle -from matplotlib.testing.decorators import image_comparison +from matplotlib.testing.decorators import image_comparison, cleanup import matplotlib.pyplot as plt import matplotlib.patches as mpatches import matplotlib.collections as mcollections @@ -203,6 +203,36 @@ def test_patch_custom_linestyle(): ax.set_ylim([-1, 2]) +@cleanup +def test_patch_linestyle_accents(): + #: Test if linestyle can also be specified with short menoics + #: like "--" + #: c.f. Gihub issue #2136 + star = mpath.Path.unit_regular_star(6) + circle = mpath.Path.unit_circle() + # concatenate the star with an internal cutout of the circle + verts = np.concatenate([circle.vertices, star.vertices[::-1]]) + codes = np.concatenate([circle.codes, star.codes]) + + linestyles = ["-", "--", "-.", ":", + "solid", "dashed", "dashdot", "dotted"] + + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1) + for i, ls in enumerate(linestyles): + star = mpath.Path(verts + i, codes) + patch = mpatches.PathPatch(star, + linewidth=3, linestyle=ls, + facecolor=(1, 0, 0), + edgecolor=(0, 0, 1)) + ax.add_patch(patch) + + ax.set_xlim([-1, i + 1]) + ax.set_ylim([-1, i + 1]) + fig.canvas.draw() + assert True + + def test_wedge_movement(): param_dict = {'center': ((0, 0), (1, 1), 'set_center'), 'r': (5, 8, 'set_radius'), diff --git a/lib/matplotlib/tests/test_triangulation.py b/lib/matplotlib/tests/test_triangulation.py index 87719c29a63d..3b26f0789f35 100644 --- a/lib/matplotlib/tests/test_triangulation.py +++ b/lib/matplotlib/tests/test_triangulation.py @@ -765,7 +765,7 @@ def z(x, y): refiner = mtri.UniformTriRefiner(triang0) tri_refi, z_test_refi = refiner.refine_field(z0, subdiv=4) levels = np.arange(0., 1., 0.025) - plt.triplot(triang0, lw=0.5, color='0.5') + plt.triplot(triang0, '0.5', lw=0.5) plt.tricontour(tri_refi, z_test_refi, levels=levels, colors="black") diff --git a/lib/matplotlib/tri/triplot.py b/lib/matplotlib/tri/triplot.py index fe0a064d8a71..d0bdc0e6fb01 100644 --- a/lib/matplotlib/tri/triplot.py +++ b/lib/matplotlib/tri/triplot.py @@ -5,6 +5,7 @@ import numpy as np from matplotlib.tri.triangulation import Triangulation +import matplotlib def triplot(ax, *args, **kwargs): @@ -54,6 +55,10 @@ def triplot(ax, *args, **kwargs): if len(args) > 0: fmt = args[0] linestyle, marker, color = matplotlib.axes._base._process_plot_format(fmt) + if linestyle is None: + linestyle = matplotlib.rcParams['lines.linestyle'] + if marker is None: + marker = matplotlib.rcParams['lines.marker'] # Insert plot format string into a copy of kwargs (kwargs values prevail). kw = kwargs.copy()