Skip to content

Commit a93f4b9

Browse files
committed
Disable miter limit in SVG, PS and Agg backends
1 parent 8411c29 commit a93f4b9

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,8 @@ def print_figure_impl():
11891189
print("%s translate"%_nums_to_str(xo, yo), file=fh)
11901190
if rotation: print("%d rotate"%rotation, file=fh)
11911191
print("%s clipbox"%_nums_to_str(width*72, height*72, 0, 0), file=fh)
1192+
# Disable any sort of miter limit
1193+
print("%s setmiterlimit" % 100000, file=fh)
11921194

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

13421346
# write the figure
13431347
print(self._pswriter.getvalue(), file=fh)

lib/matplotlib/backends/backend_svg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ def _write_default_style(self):
297297
writer = self.writer
298298
default_style = generate_css({
299299
'stroke-linejoin': 'round',
300-
'stroke-linecap': 'butt'})
300+
'stroke-linecap': 'butt',
301+
# Disable the miter limit. 100000 seems to be close to
302+
# the maximum that renderers support before breaking.
303+
'stroke-miterlimit': '100000'})
301304
writer.start('defs')
302305
writer.start('style', type='text/css')
303306
writer.data('*{%s}\n' % default_style)

lib/matplotlib/tests/test_colorbar.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
from numpy import ma
88
import matplotlib
9+
from matplotlib import rc_context
910
from matplotlib.testing.decorators import image_comparison, cleanup
1011
import matplotlib.pyplot as plt
1112
from matplotlib import rcParams
@@ -258,27 +259,27 @@ def test_colorbarbase():
258259
baseline_images=['colorbar_closed_patch'],
259260
remove_text=True)
260261
def test_colorbar_closed_patch():
261-
fig = plt.figure(figsize=(8,6))
262+
fig = plt.figure(figsize=(8, 6))
262263
ax1 = fig.add_axes([0.05, 0.85, 0.9, 0.1])
263264
ax2 = fig.add_axes([0.05, 0.65, 0.9, 0.1])
264265
ax3 = fig.add_axes([0.05, 0.45, 0.9, 0.1])
265266
ax4 = fig.add_axes([0.05, 0.25, 0.9, 0.1])
266267
ax5 = fig.add_axes([0.05, 0.05, 0.9, 0.1])
267268

268-
cmap = cm.jet
269-
cmap.set_under('w')
270-
cmap.set_over('w')
271-
272-
im = ax1.pcolormesh(np.linspace(0,10,16).reshape((4,4)))
269+
cmap = get_cmap("RdBu", lut=5)
273270

274-
plt.colorbar(im,cax=ax2,cmap=cmap,orientation='horizontal',
275-
extend='both',extendfrac=0.5)
276-
plt.colorbar(im,cax=ax3,cmap=cmap,orientation='horizontal',
277-
extend='both',)
278-
plt.colorbar(im,cax=ax4,cmap=cmap,orientation='horizontal',
279-
extend='both',extendrect=True)
280-
plt.colorbar(im,cax=ax5,cmap=cmap,orientation='horizontal',
281-
extend='neither')
271+
im = ax1.pcolormesh(np.linspace(0, 10, 16).reshape((4, 4)), cmap=cmap)
272+
values = np.linspace(0, 10, 5)
273+
274+
with rc_context({'axes.linewidth': 16}):
275+
plt.colorbar(im, cax=ax2, cmap=cmap, orientation='horizontal',
276+
extend='both', extendfrac=0.5, values=values)
277+
plt.colorbar(im, cax=ax3, cmap=cmap, orientation='horizontal',
278+
extend='both', values=values)
279+
plt.colorbar(im, cax=ax4, cmap=cmap, orientation='horizontal',
280+
extend='both', extendrect=True, values=values)
281+
plt.colorbar(im, cax=ax5, cmap=cmap, orientation='horizontal',
282+
extend='neither', values=values)
282283

283284

284285
if __name__ == '__main__':

src/_backend_agg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
417417
stroke.width(points_to_pixels(gc.linewidth));
418418
stroke.line_cap(gc.cap);
419419
stroke.line_join(gc.join);
420+
stroke.miter_limit(points_to_pixels(gc.linewidth));
420421
theRasterizer.add_path(stroke);
421422
} else {
422423
dash_t dash(path);
@@ -425,6 +426,7 @@ RendererAgg::_draw_path(path_t &path, bool has_clippath, const facepair_t &face,
425426
stroke.line_cap(gc.cap);
426427
stroke.line_join(gc.join);
427428
stroke.width(linewidth);
429+
stroke.miter_limit(points_to_pixels(gc.linewidth));
428430
theRasterizer.add_path(stroke);
429431
}
430432

@@ -564,6 +566,7 @@ inline void RendererAgg::draw_markers(GCAgg &gc,
564566
stroke.width(points_to_pixels(gc.linewidth));
565567
stroke.line_cap(gc.cap);
566568
stroke.line_join(gc.join);
569+
stroke.miter_limit(points_to_pixels(gc.linewidth));
567570
theRasterizer.reset();
568571
theRasterizer.add_path(stroke);
569572
agg::render_scanlines(theRasterizer, slineP8, scanlines);

0 commit comments

Comments
 (0)