diff --git a/lib/matplotlib/tests/baseline_images/test_path/nan_path.eps b/lib/matplotlib/tests/baseline_images/test_path/nan_path.eps new file mode 100644 index 000000000000..48d473aa3f09 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_path/nan_path.eps @@ -0,0 +1,455 @@ +%!PS-Adobe-3.0 EPSF-3.0 +%%Title: /home/tcaswell/source/p/matplotlib/result_images/test_path/nan_path.eps +%%Creator: matplotlib version 2.0.0.post99.dev0+gcdc493d33, http://matplotlib.org/ +%%CreationDate: Tue Mar 14 16:50:24 2017 +%%Orientation: portrait +%%BoundingBox: 75 223 536 568 +%%EndComments +%%BeginProlog +/mpldict 7 dict def +mpldict begin +/m { moveto } bind def +/l { lineto } bind def +/r { rlineto } bind def +/c { curveto } bind def +/cl { closepath } bind def +/box { +m +1 index 0 r +0 exch r +neg 0 r +cl +} bind def +/clipbox { +box +clip +newpath +} bind def +end +%%EndProlog +mpldict begin +75.6 223.2 translate +460.8 345.6 0 0 clipbox +gsave +0 0 m +460.8 0 l +460.8 345.6 l +0 345.6 l +cl +1.000 setgray +fill +grestore +gsave +57.6 38.016 m +414.72 38.016 l +414.72 304.128 l +57.6 304.128 l +cl +1.000 setgray +fill +grestore +0.800 setlinewidth +1 setlinejoin +0 setlinecap +[] 0 setdash +0.000 setgray +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +73.8327 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +127.942 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +182.051 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +236.16 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +290.269 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +344.378 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +0 -3.5 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +398.487 38.016 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 50.112 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 90.432 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 130.752 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 171.072 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 211.392 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 251.712 o +grestore +gsave +/o { +gsave +newpath +translate +0.8 setlinewidth +1 setlinejoin +0 setlinecap +0 0 m +-3.5 0 l + +gsave +0.000 setgray +fill +grestore +stroke +grestore +} bind def +57.6 292.032 o +grestore +1.500 setlinewidth +2 setlinecap +0.122 0.467 0.706 setrgbcolor +gsave +357.1 266.1 57.6 38.02 clipbox +73.832727 50.112 m +182.050909 90.432 m +290.269091 130.752 m +344.378182 150.912 l +398.487273 171.072 l +stroke +grestore +1.000 setlinewidth +0 setlinecap +gsave +357.1 266.1 57.6 38.02 clipbox +/o { +gsave +newpath +translate +1.0 setlinewidth +1 setlinejoin +0 setlinecap +0 -3 m +0.795609 -3 1.55874 -2.683901 2.12132 -2.12132 c +2.683901 -1.55874 3 -0.795609 3 0 c +3 0.795609 2.683901 1.55874 2.12132 2.12132 c +1.55874 2.683901 0.795609 3 0 3 c +-0.795609 3 -1.55874 2.683901 -2.12132 2.12132 c +-2.683901 1.55874 -3 0.795609 -3 0 c +-3 -0.795609 -2.683901 -1.55874 -2.12132 -2.12132 c +-1.55874 -2.683901 -0.795609 -3 0 -3 c +cl + +gsave +0.122 0.467 0.706 setrgbcolor +fill +grestore +stroke +grestore +} bind def +73.8327 50.112 o +182.051 90.432 o +290.269 130.752 o +344.378 150.912 o +398.487 171.072 o +grestore +1.500 setlinewidth +2 setlinecap +1.000 0.498 0.055 setrgbcolor +gsave +357.1 266.1 57.6 38.02 clipbox +127.941818 191.232 m +236.16 231.552 m +290.269091 251.712 l +398.487273 292.032 m +stroke +grestore +1.000 setlinewidth +0 setlinecap +gsave +357.1 266.1 57.6 38.02 clipbox +/o { +gsave +newpath +translate +1.0 setlinewidth +1 setlinejoin +0 setlinecap +0 -3 m +0.795609 -3 1.55874 -2.683901 2.12132 -2.12132 c +2.683901 -1.55874 3 -0.795609 3 0 c +3 0.795609 2.683901 1.55874 2.12132 2.12132 c +1.55874 2.683901 0.795609 3 0 3 c +-0.795609 3 -1.55874 2.683901 -2.12132 2.12132 c +-2.683901 1.55874 -3 0.795609 -3 0 c +-3 -0.795609 -2.683901 -1.55874 -2.12132 -2.12132 c +-1.55874 -2.683901 -0.795609 -3 0 -3 c +cl + +gsave +1.000 0.498 0.055 setrgbcolor +fill +grestore +stroke +grestore +} bind def +127.942 191.232 o +236.16 231.552 o +290.269 251.712 o +398.487 292.032 o +grestore +0.800 setlinewidth +0 setlinejoin +2 setlinecap +[] 0 setdash +0.000 setgray +gsave +57.6 38.016 m +57.6 304.128 l +stroke +grestore +gsave +414.72 38.016 m +414.72 304.128 l +stroke +grestore +gsave +57.6 38.016 m +414.72 38.016 l +stroke +grestore +gsave +57.6 304.128 m +414.72 304.128 l +stroke +grestore + +end +showpage diff --git a/lib/matplotlib/tests/baseline_images/test_path/nan_path.pdf b/lib/matplotlib/tests/baseline_images/test_path/nan_path.pdf new file mode 100644 index 000000000000..5734691b4e1a Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_path/nan_path.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_path/nan_path.png b/lib/matplotlib/tests/baseline_images/test_path/nan_path.png new file mode 100644 index 000000000000..199059655446 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_path/nan_path.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_path/nan_path.svg b/lib/matplotlib/tests/baseline_images/test_path/nan_path.svg new file mode 100644 index 000000000000..e75b5341d4bc --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_path/nan_path.svg @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 6f1e57eed3d4..7964447b9fea 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -117,6 +117,19 @@ def test_marker_paths_pdf(): plt.ylim(-1, 7) +@image_comparison(baseline_images=['nan_path'], style='default', + remove_text=True, extensions=['pdf', 'svg', 'eps', 'png']) +def test_nan_isolated_points(): + + y0 = [0, np.nan, 2, np.nan, 4, 5, 6] + y1 = [np.nan, 7, np.nan, 9, 10, np.nan, 12] + + fig, ax = plt.subplots() + + ax.plot(y0, '-o') + ax.plot(y1, '-o') + + def test_path_no_doubled_point_in_to_polygon(): hand = np.array( [[1.64516129, 1.16145833], diff --git a/src/path_converters.h b/src/path_converters.h index d19b17dc17ae..3150b18edd5b 100644 --- a/src/path_converters.h +++ b/src/path_converters.h @@ -343,6 +343,7 @@ class PathClipper : public EmbeddedQueue<3> unsigned vertex(double *x, double *y) { unsigned code; + bool emit_moveto = false; if (m_do_clipping) { /* This is the slow path where we actually do clipping */ @@ -352,6 +353,8 @@ class PathClipper : public EmbeddedQueue<3> } while ((code = m_source->vertex(x, y)) != agg::path_cmd_stop) { + emit_moveto = false; + switch (code) { case (agg::path_cmd_end_poly | agg::path_flags_close): if (m_has_init) { @@ -363,10 +366,30 @@ class PathClipper : public EmbeddedQueue<3> goto exit_loop; case agg::path_cmd_move_to: + + // was the last command a moveto (and we have + // seen at least one command ? + // if so, shove it in the queue if in clip box + if (m_moveto && m_has_init && + m_lastX >= m_cliprect.x1 && + m_lastX <= m_cliprect.x2 && + m_lastY >= m_cliprect.y1 && + m_lastY <= m_cliprect.y2) { + // push the last moveto onto the queue + queue_push(agg::path_cmd_move_to, m_lastX, m_lastY); + // flag that we need to emit it + emit_moveto = true; + } + // update the internal state for this moveto m_initX = m_lastX = *x; m_initY = m_lastY = *y; m_has_init = true; m_moveto = true; + // if the last command was moveto exit the loop to emit the code + if (emit_moveto) { + goto exit_loop; + } + // else, break and get the next point break; case agg::path_cmd_line_to: