Skip to content

Commit 4dd97d5

Browse files
committed
Merge pull request matplotlib#3722 from mdboom/fix-markers-with-nans
BUG : fix fill_between with semilog merged by hand because I added a test-clean up commit
2 parents 50625de + ae377f7 commit 4dd97d5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/matplotlib/tests/test_agg.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ def report_memory(i):
131131
## # w/ text and w/ write_png : Average memory consumed per loop: 0.32
132132

133133

134+
@cleanup
135+
def test_marker_with_nan():
136+
# This creates a marker with nans in it, which was segfaulting the
137+
# Agg backend (see #3722)
138+
fig, ax = plt.subplots(1)
139+
steps = 1000
140+
data = np.arange(steps)
141+
ax.semilogx(data)
142+
ax.fill_between(data, data*0.8, data*1.2)
143+
buf = io.BytesIO()
144+
fig.savefig(buf, format='png')
145+
146+
134147
if __name__ == "__main__":
135148
import nose
136149
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

src/_backend_agg.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ Py::Object
665665
RendererAgg::draw_markers(const Py::Tuple& args)
666666
{
667667
typedef agg::conv_transform<PathIterator> transformed_path_t;
668-
typedef PathSnapper<transformed_path_t> snap_t;
668+
typedef PathNanRemover<transformed_path_t> nan_removed_t;
669+
typedef PathSnapper<nan_removed_t> snap_t;
669670
typedef agg::conv_curve<snap_t> curve_t;
670671
typedef agg::conv_stroke<curve_t> stroke_t;
671672
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
@@ -693,15 +694,17 @@ RendererAgg::draw_markers(const Py::Tuple& args)
693694

694695
PathIterator marker_path(marker_path_obj);
695696
transformed_path_t marker_path_transformed(marker_path, marker_trans);
696-
snap_t marker_path_snapped(marker_path_transformed,
697+
nan_removed_t marker_path_nan_removed(marker_path_transformed, true, marker_path.has_curves());
698+
snap_t marker_path_snapped(marker_path_nan_removed,
697699
gc.snap_mode,
698700
marker_path.total_vertices(),
699701
gc.linewidth);
700702
curve_t marker_path_curve(marker_path_snapped);
701703

702704
PathIterator path(path_obj);
703705
transformed_path_t path_transformed(path, trans);
704-
snap_t path_snapped(path_transformed,
706+
nan_removed_t path_nan_removed(path_transformed, false, false);
707+
snap_t path_snapped(path_nan_removed,
705708
SNAP_FALSE,
706709
path.total_vertices(),
707710
0.0);

0 commit comments

Comments
 (0)