diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 8a34f97c389a..5706dda3aed1 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -91,10 +91,12 @@ def stackplot(axes, x, *args, **kwargs): m, n = y.shape center = np.zeros(n) total = np.sum(y, 0) + # multiply by 1/total (or zero) to avoid infinities in the division: + inv_total = np.where(total > 0, 1./total, 0) increase = np.hstack((y[:, 0:1], np.diff(y))) below_size = total - stack below_size += 0.5 * y - move_up = below_size / total + move_up = below_size * inv_total move_up[:, 0] = 0.5 center = (move_up - 0.5) * increase center = np.cumsum(center.sum(0)) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.pdf b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.pdf index 412a798a6702..531c9c5e9b3f 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.png b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.png index f59650bd8552..d4082631fdec 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.png and b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.svg b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.svg index b1fdb22b2da3..ec64d7cdbf4e 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/stackplot_test_baseline.svg @@ -179,7 +179,7 @@ L 181.570909 -231.760398 L 179.541818 -231.80983 L 177.512727 -231.899904 L 175.483636 -232.057755 -L 173.454545 -232.323693 +L 173.454545 -231.709091 L 171.425455 -232.754218 L 169.396364 -233.423569 L 167.367273 -234.422298 @@ -231,10 +231,10 @@ L 76.058182 -231.709091 L 74.029091 -231.709091 L 72 -231.709091 z -" id="mbf9a7b4bdc" style="stroke:#000000;"/> +" id="m6cb1cbab74" style="stroke:#000000;"/> - - + + @@ -290,7 +290,7 @@ L 165.338182 -235.851202 L 167.367273 -234.422298 L 169.396364 -233.423569 L 171.425455 -232.754218 -L 173.454545 -232.323693 +L 173.454545 -231.709091 L 175.483636 -232.057755 L 177.512727 -231.899904 L 179.541818 -231.80983 @@ -390,7 +390,7 @@ L 181.570909 -261.669355 L 179.541818 -261.80151 L 177.512727 -260.817778 L 175.483636 -259.342121 -L 173.454545 -258.054863 +L 173.454545 -231.709091 L 171.425455 -257.500993 L 169.396364 -257.979549 L 167.367273 -259.535461 @@ -442,10 +442,10 @@ L 76.058182 -231.709091 L 74.029091 -231.709091 L 72 -231.709091 z -" id="mfcdae51249" style="stroke:#000000;"/> +" id="mabe8d8b890" style="stroke:#000000;"/> - - + + @@ -501,7 +501,7 @@ L 165.338182 -262.026809 L 167.367273 -259.535461 L 169.396364 -257.979549 L 171.425455 -257.500993 -L 173.454545 -258.054863 +L 173.454545 -231.709091 L 175.483636 -259.342121 L 177.512727 -260.817778 L 179.541818 -261.80151 @@ -601,7 +601,7 @@ L 181.570909 -262.836539 L 179.541818 -262.61169 L 177.512727 -261.36992 L 175.483636 -259.711564 -L 173.454545 -258.297563 +L 173.454545 -231.709091 L 171.425455 -257.657531 L 169.396364 -258.078677 L 167.367273 -259.597092 @@ -653,10 +653,10 @@ L 76.058182 -231.709127 L 74.029091 -231.7091 L 72 -231.709093 z -" id="mbe9093e089" style="stroke:#000000;"/> +" id="mb180dc7e7c" style="stroke:#000000;"/> - - + + @@ -685,80 +685,80 @@ L 274.909091 43.2 +" id="ma2a1b7f8ab" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="m3e9ceeb88a" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + @@ -769,92 +769,92 @@ L 0 4 +" id="m2aa3cbf442" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="mff6146e961" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -922,7 +922,7 @@ L 408.829091 -295.076876 L 410.858182 -296.310545 L 412.887273 -297.069753 L 414.916364 -297.280326 -L 416.945455 -296.96031 +L 416.945455 -310.254545 L 418.974545 -296.253309 L 421.003636 -295.424131 L 423.032727 -294.803246 @@ -1022,7 +1022,7 @@ L 425.061818 -294.742128 L 423.032727 -294.903985 L 421.003636 -295.614944 L 418.974545 -296.601973 -L 416.945455 -297.574912 +L 416.945455 -310.254545 L 414.916364 -298.325453 L 412.887273 -298.784231 L 410.858182 -299.023751 @@ -1074,10 +1074,10 @@ L 319.549091 -310.254527 L 317.52 -310.254541 L 315.490909 -310.254544 z -" id="ma6d91e7c29" style="stroke:#000000;"/> +" id="m2e6dd64b73" style="stroke:#000000;"/> - - + + @@ -1133,7 +1133,7 @@ L 408.829091 -299.218987 L 410.858182 -299.023751 L 412.887273 -298.784231 L 414.916364 -298.325453 -L 416.945455 -297.574912 +L 416.945455 -310.254545 L 418.974545 -296.601973 L 421.003636 -295.614944 L 423.032727 -294.903985 @@ -1233,7 +1233,7 @@ L 425.061818 -324.651085 L 423.032727 -324.895665 L 421.003636 -324.532818 L 418.974545 -323.88634 -L 416.945455 -323.306081 +L 416.945455 -310.254545 L 414.916364 -323.072227 L 412.887273 -323.34021 L 410.858182 -324.136915 @@ -1285,10 +1285,10 @@ L 319.549091 -310.254527 L 317.52 -310.254541 L 315.490909 -310.254544 z -" id="m9ed35b237c" style="stroke:#000000;"/> +" id="m7541faab5a" style="stroke:#000000;"/> - - + + @@ -1344,7 +1344,7 @@ L 408.829091 -325.394594 L 410.858182 -324.136915 L 412.887273 -323.34021 L 414.916364 -323.072227 -L 416.945455 -323.306081 +L 416.945455 -310.254545 L 418.974545 -323.88634 L 421.003636 -324.532818 L 423.032727 -324.895665 @@ -1444,7 +1444,7 @@ L 425.061818 -325.818269 L 423.032727 -325.705845 L 421.003636 -325.08496 L 418.974545 -324.255782 -L 416.945455 -323.548781 +L 416.945455 -310.254545 L 414.916364 -323.228765 L 412.887273 -323.439338 L 410.858182 -324.198546 @@ -1496,10 +1496,10 @@ L 319.549091 -310.254564 L 317.52 -310.25455 L 315.490909 -310.254546 z -" id="m6440925e5d" style="stroke:#000000;"/> +" id="mddced2f8b3" style="stroke:#000000;"/> - - + + @@ -1526,72 +1526,72 @@ L 518.4 43.2 - + - + - + - + - + - + - + - + - + - + - + - + @@ -1600,84 +1600,84 @@ L 518.4 43.2 - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1745,7 +1745,7 @@ L 165.338182 -96.342533 L 167.367273 -97.815082 L 169.396364 -98.761896 L 171.425455 -99.150033 -L 173.454545 -99.023358 +L 173.454545 -110.524675 L 175.483636 -98.529552 L 177.512727 -97.916128 L 179.541818 -97.483402 @@ -1845,7 +1845,7 @@ L 181.570909 -97.54714 L 179.541818 -97.569749 L 177.512727 -98.079682 L 175.483636 -98.828407 -L 173.454545 -99.55016 +L 173.454545 -110.524675 L 171.425455 -100.045856 L 169.396364 -100.231448 L 167.367273 -100.140687 @@ -1897,10 +1897,10 @@ L 76.058182 -110.52467 L 74.029091 -110.524674 L 72 -110.524675 z -" id="mc352e45df1" style="stroke:#000000;"/> +" id="m9dddbfb1d5" style="stroke:#000000;"/> - - + + @@ -1956,7 +1956,7 @@ L 165.338182 -99.892914 L 167.367273 -100.140687 L 169.396364 -100.231448 L 171.425455 -100.045856 -L 173.454545 -99.55016 +L 173.454545 -110.524675 L 175.483636 -98.828407 L 177.512727 -98.079682 L 179.541818 -97.569749 @@ -2056,7 +2056,7 @@ L 181.570909 -123.183389 L 179.541818 -123.276904 L 177.512727 -122.866432 L 175.483636 -122.215007 -L 173.454545 -121.605448 +L 173.454545 -110.524675 L 171.425455 -121.257377 L 169.396364 -121.279431 L 167.367273 -121.666256 @@ -2108,10 +2108,10 @@ L 76.058182 -110.52467 L 74.029091 -110.524674 L 72 -110.524675 z -" id="m6f495adba9" style="stroke:#000000;"/> +" id="mf798e8e8a4" style="stroke:#000000;"/> - - + + @@ -2167,7 +2167,7 @@ L 165.338182 -122.329148 L 167.367273 -121.666256 L 169.396364 -121.279431 L 171.425455 -121.257377 -L 173.454545 -121.605448 +L 173.454545 -110.524675 L 175.483636 -122.215007 L 177.512727 -122.866432 L 179.541818 -123.276904 @@ -2267,7 +2267,7 @@ L 181.570909 -124.183832 L 179.541818 -123.971344 L 177.512727 -123.339696 L 175.483636 -122.531672 -L 173.454545 -121.813477 +L 173.454545 -110.524675 L 171.425455 -121.391553 L 169.396364 -121.364398 L 167.367273 -121.719083 @@ -2319,10 +2319,10 @@ L 76.058182 -110.524701 L 74.029091 -110.524682 L 72 -110.524677 z -" id="m4b85bd7af5" style="stroke:#000000;"/> +" id="m07fcee0628" style="stroke:#000000;"/> - - + + @@ -2349,72 +2349,72 @@ L 274.909091 231.709091 - + - + - + - + - + - + - + - + - + - + - + - + @@ -2423,96 +2423,96 @@ L 274.909091 231.709091 - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -2529,635 +2529,635 @@ z - +" id="m1e7a726d58" style="stroke:#000000;"/> - - + + - +" id="m78f9612d6c" style="stroke:#000000;"/> - - + + - +" id="m2c3a120f05" style="stroke:#000000;"/> - - + + @@ -3184,72 +3184,72 @@ L 518.4 231.709091 - + - + - + - + - + - + - + - + - + - + - + - + @@ -3258,96 +3258,84 @@ L 518.4 231.709091 - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - + @@ -3355,17 +3343,17 @@ L 518.4 231.709091 - - + + - - + + - - + + - - + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 45c2bb679db2..c9c11c7edfe3 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1392,6 +1392,7 @@ def bump(a): return a d = layers(3, 100) + d[50,:] = 0 # test for fixed weighted wiggle (issue #6313) fig = plt.figure()