Skip to content

Commit

Permalink
Disable miter limit in SVG, PS and Agg backends
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Mar 4, 2015
1 parent 2f932e1 commit 3b63c19
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions lib/matplotlib/backends/backend_ps.py
Expand Up @@ -1189,6 +1189,8 @@ def print_figure_impl():
print("%s translate"%_nums_to_str(xo, yo), file=fh)
if rotation: print("%d rotate"%rotation, file=fh)
print("%s clipbox"%_nums_to_str(width*72, height*72, 0, 0), file=fh)
# Disable any sort of miter limit
print("%s setmiterlimit" % 100000, file=fh)

# write the figure
content = self._pswriter.getvalue()
Expand Down Expand Up @@ -1338,6 +1340,8 @@ def write(self, *kl, **kwargs):
#print >>fh, "gsave"
print("%s translate"%_nums_to_str(xo, yo), file=fh)
print("%s clipbox"%_nums_to_str(width*72, height*72, 0, 0), file=fh)
# Disable any sort of miter limit
print("%d setmiterlimit" % 100000, file=fh)

# write the figure
print(self._pswriter.getvalue(), file=fh)
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/backends/backend_svg.py
Expand Up @@ -297,7 +297,10 @@ def _write_default_style(self):
writer = self.writer
default_style = generate_css({
'stroke-linejoin': 'round',
'stroke-linecap': 'butt'})
'stroke-linecap': 'butt',
# Disable the miter limit. 100000 seems to be close to
# the maximum that renderers support before breaking.
'stroke-miterlimit': '100000'})
writer.start('defs')
writer.start('style', type='text/css')
writer.data('*{%s}\n' % default_style)
Expand Down
29 changes: 15 additions & 14 deletions lib/matplotlib/tests/test_colorbar.py
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from numpy import ma
import matplotlib
from matplotlib import rc_context
from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
from matplotlib import rcParams
Expand Down Expand Up @@ -258,27 +259,27 @@ def test_colorbarbase():
baseline_images=['colorbar_closed_patch'],
remove_text=True)
def test_colorbar_closed_patch():
fig = plt.figure(figsize=(8,6))
fig = plt.figure(figsize=(8, 6))
ax1 = fig.add_axes([0.05, 0.85, 0.9, 0.1])
ax2 = fig.add_axes([0.1, 0.65, 0.75, 0.1])
ax3 = fig.add_axes([0.05, 0.45, 0.9, 0.1])
ax4 = fig.add_axes([0.05, 0.25, 0.9, 0.1])
ax5 = fig.add_axes([0.05, 0.05, 0.9, 0.1])

cmap = cm.jet
cmap.set_under('w')
cmap.set_over('w')

im = ax1.pcolormesh(np.linspace(0,10,16).reshape((4,4)))
cmap = get_cmap("RdBu", lut=5)

plt.colorbar(im,cax=ax2,cmap=cmap,orientation='horizontal',
extend='both',extendfrac=0.5)
plt.colorbar(im,cax=ax3,cmap=cmap,orientation='horizontal',
extend='both',)
plt.colorbar(im,cax=ax4,cmap=cmap,orientation='horizontal',
extend='both',extendrect=True)
plt.colorbar(im,cax=ax5,cmap=cmap,orientation='horizontal',
extend='neither')
im = ax1.pcolormesh(np.linspace(0, 10, 16).reshape((4, 4)), cmap=cmap)
values = np.linspace(0, 10, 5)

with rc_context({'axes.linewidth': 16}):
plt.colorbar(im, cax=ax2, cmap=cmap, orientation='horizontal',
extend='both', extendfrac=0.5, values=values)
plt.colorbar(im, cax=ax3, cmap=cmap, orientation='horizontal',
extend='both', values=values)
plt.colorbar(im, cax=ax4, cmap=cmap, orientation='horizontal',
extend='both', extendrect=True, values=values)
plt.colorbar(im, cax=ax5, cmap=cmap, orientation='horizontal',
extend='neither', values=values)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions src/_backend_agg.h
Expand Up @@ -417,6 +417,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
stroke.width(points_to_pixels(gc.linewidth));
stroke.line_cap(gc.cap);
stroke.line_join(gc.join);
stroke.miter_limit(points_to_pixels(gc.linewidth));
theRasterizer.add_path(stroke);
} else {
dash_t dash(path);
Expand All @@ -425,6 +426,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
stroke.line_cap(gc.cap);
stroke.line_join(gc.join);
stroke.width(linewidth);
stroke.miter_limit(points_to_pixels(gc.linewidth));
theRasterizer.add_path(stroke);
}

Expand Down Expand Up @@ -564,6 +566,7 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
stroke.width(points_to_pixels(gc.linewidth));
stroke.line_cap(gc.cap);
stroke.line_join(gc.join);
stroke.miter_limit(points_to_pixels(gc.linewidth));
theRasterizer.reset();
theRasterizer.add_path(stroke);
agg::render_scanlines(theRasterizer, slineP8, scanlines);
Expand Down

0 comments on commit 3b63c19

Please sign in to comment.