diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 4c4daeb33df5..dee9b5336925 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -276,14 +276,16 @@ def set_linecap(self, linecap, store=1): def set_linedash(self, offset, seq, store=1): if self.linedash is not None: oldo, oldseq = self.linedash - if seq_allequal(seq, oldseq): return + if seq_allequal(seq, oldseq) and oldo == offset: + return if seq is not None and len(seq): s="[%s] %d setdash\n"%(_nums_to_str(*seq), offset) self._pswriter.write(s) else: self._pswriter.write("[] 0 setdash\n") - if store: self.linedash = (offset,seq) + if store: + self.linedash = (offset, seq) def set_font(self, fontname, fontsize, store=1): if rcParams['ps.useafm']: return diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 2005adf998df..f8aada39b927 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -346,6 +346,7 @@ def __init__(self, xdata, ydata, self.set_markersize(markersize) self._dashSeq = None + self._dashOffset = 0 self._markeredgecolor = None self._markeredgewidth = None @@ -1028,6 +1029,7 @@ def set_linestyle(self, ls): raise ValueError() self.set_dashes(ls[1]) + self._dashOffset = ls[0] self._linestyle = "--" return @@ -1198,7 +1200,7 @@ def _draw_solid(self, renderer, 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) + gc.set_dashes(self._dashOffset, self._dashSeq) renderer.draw_path(gc, path, trans) @@ -1222,6 +1224,7 @@ def update_from(self, other): self._markeredgecolor = other._markeredgecolor self._markeredgewidth = other._markeredgewidth self._dashSeq = other._dashSeq + self._dashOffset = other._dashOffset self._dashcapstyle = other._dashcapstyle self._dashjoinstyle = other._dashjoinstyle self._solidcapstyle = other._solidcapstyle diff --git a/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.pdf b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.pdf new file mode 100644 index 000000000000..486d6a723afb Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.png b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.png new file mode 100644 index 000000000000..d33a42cd46a4 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.svg b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.svg new file mode 100644 index 000000000000..f82e44d0784d --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_axes/dash_offset.svg @@ -0,0 +1,2874 @@ + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 5a3e6ee70e13..02071022b74d 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4102,12 +4102,14 @@ def test_shared_scale(): assert_equal(ax.get_yscale(), 'linear') assert_equal(ax.get_xscale(), 'linear') + @cleanup def test_violin_point_mass(): """Violin plot should handle point mass pdf gracefully.""" plt.violinplot(np.array([0, 0])) + @cleanup def test_axisbg_warning(): fig = plt.figure() @@ -4118,6 +4120,17 @@ def test_axisbg_warning(): ("The axisbg attribute was deprecated in version 2.0."))) +@image_comparison(baseline_images=["dash_offset"], remove_text=True) +def test_dash_offset(): + fig, ax = plt.subplots() + x = np.linspace(0, 10) + y = np.ones_like(x) + for j in range(0, 100, 2): + ax.plot(x, j*y, ls=(j, (10, 10)), lw=5, color='k') + plt.show() + + + if __name__ == '__main__': import nose import sys diff --git a/src/_backend_agg_basic_types.h b/src/_backend_agg_basic_types.h index cea2b7e14f0f..c19b259eaa8c 100644 --- a/src/_backend_agg_basic_types.h +++ b/src/_backend_agg_basic_types.h @@ -63,6 +63,7 @@ class Dashes } stroke.add_dash(val0, val1); } + stroke.dash_start(get_dash_offset() * dpi / 72.0); } };
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: