8000 NaN causes plt.vlines to not scale y limits · Issue #7406 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

NaN causes plt.vlines to not scale y limits #7406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks
dadkins opened this issue Nov 4, 2016 · 2 comments · Fixed by #7408
Closed
2 tasks

NaN causes plt.vlines to not scale y limits #7406

dadkins opened this issue Nov 4, 2016 · 2 comments · Fixed by #7408
Assignees
Milestone

Comments

@dadkins
Copy link
dadkins commented Nov 4, 2016

I have reduced the error to the following code snippet which I run in a Jupyter notebook. A NaN as the first item in the series causes plt.vlines to not scale the y limits appropriately. The data values are in the thousands, but the ylimits are [-0.06, 0.06].

%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sys

print sys.version
print 'pandas', pd.__version__
print 'matplotlib', matplotlib.__version__
df = pd.DataFrame(index = pd.DatetimeIndex(['2016-10-07', '2016-10-14', '2016-10-21', '2016-10-28'], name='Date'),
                  data = [np.nan, -1000, -3000, 4500],
                  columns = ['Amount'])
print df

plt.figure(figsize=(12,3))
plt.vlines(df.index, 0, df['Amount'])
2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
pandas 0.19.0
matplotlib 1.5.3
            Amount
Date              
2016-10-07     NaN
2016-10-14 -1000.0
2016-10-21 -3000.0
2016-10-28  4500.0
  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...)
    1.5.3, python 2.7.12, Linux

  • How did you install Matplotlib and Python (pip, anaconda, from source ...)
    conda

  • [ ]
    matplotlib-bug

@phobson
Copy link
Member
phobson commented Nov 4, 2016

Thanks for the clear and detailed report. I can confirm this.

I can also confirm that moving to null value to a position other than the first in the sequence results in properly scaled axes.

An even more minimal example would be:

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.vlines([1, 2, 3, 4], 0, [np.nan, -1000, -3000, 4500], colors='b', linewidth=5)

Of the top of my head, one way to fix this would be to check that the first element isn't null and remove it if it is. However, that feels like treating the symptom and not the cause.

Will need to dig further.

@phobson phobson added this to the 2.0.1 (next bug fix release) milestone Nov 4, 2016
@phobson phobson self-assigned this Nov 4, 2016
@tacaswell
Copy link
Member

We are probably using np.min instead of np.nanmin and/or not masking the input properly.

phobson added a commit to phobson/matplotlib that referenced this issue Nov 4, 2016
phobson added a commit to phobson/matplotlib that referenced this issue Nov 4, 2016
Closes GH matplotlib#7406. Also applied fixes to Axes.hlines
and wrote tests for both.
phobson added a commit to phobson/matplotlib that referenced this issue Nov 7, 2016
Closes GH matplotlib#7406. Also applied fixes to Axes.hlines
and wrote tests for both.
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0