Skip to content

weighted_wiggle stackplot fails when all lines are zero at same x #6313

Closed

Description

@egpbos

When using stackplot(..., baseline='weighted_wiggle') if all y arrays contain zero at some (interval of) x the plot stops rendering after that zero point.

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y = np.random.random(10)
y2 = np.random.random(10)
y3 = np.random.random(10)

y[5] = 0
y3[5] = 0

fig, ax = plt.subplots(3,2, figsize=(12,8))

ax[0,0].stackplot(x, y, baseline='sym')
ax[0,1].stackplot(x, y, baseline='weighted_wiggle')
ax[1,0].stackplot(x, y, y2, baseline='sym')
ax[1,1].stackplot(x, y, y2, baseline='weighted_wiggle')
ax[2,0].stackplot(x, y, y3, baseline='sym')
ax[2,1].stackplot(x, y, y3, baseline='weighted_wiggle')

ax[0,0].set_title('sym: no problem')
ax[0,1].set_title('failed: stops after zero `y` (x>4)')
ax[1,1].set_title('success: non-zero `y2` saves the day')
ax[2,1].set_title('failed: stops after zero `y` and `y3` (x>4)')

plt.tight_layout()
plt.show()

I have this issue with Matplotlib 1.5.1, installed via pip, with Python 2.7.10 on Ubuntu Linux 15.10.

Activity

  1. tacaswell commented on Apr 28, 2016

    @tacaswell
    Member

    The problem is that there is the weighting which divides by the total weight to sort out how much to move the base line up or down. This results in a np.inf being throw in which (correctly) does not plot.

    @egpbos Do you understand the underlying algorithm well enough to sort out what to do in this case?

    reference from source http://leebyron.com/streamgraph/

  2. tacaswell commented on Apr 28, 2016

    @tacaswell
    Member
  3. added this to the milestone on Apr 28, 2016
  4. modified the milestones: , on May 3, 2017
  5. modified the milestones: , on Oct 9, 2017
  6. egpbos commented on Jul 10, 2018

    @egpbos
    ContributorAuthor

    On the left the old result, on the right the result with matplotlib 2.2.2.
    schermafbeelding 2018-07-10 om 11 29 32

    I'm not sure whether this is completely expected behavior, especially the right-hand part which seems too high. But I would say the zero-issue is at least solved :)

  7. dstansby commented on Jul 21, 2019

    @dstansby
    Member

    Going to close this as fixed, feel free to comment or re-open if I've missed something.

  8. removed this from the future releases milestone on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions