FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

boxplot: positions used to take Int64Index · Issue #10022 · matplotlib/matplotlib · GitHub

Repository navigation

boxplot: positions used to take Int64Index #10022

Closed

Description

Bug report

I upgraded matplotlib recently and my boxplot stopped working. I realized it was the keyword positions which was taking in a Int64Index array created by pandas. Using Int64Index.values fixes this, but plot takes a Int64Index array so can't see why it isn't desirable for boxplot or why it was removed/no longer works.

Code for reproduction

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = np.random.rand(5,2)
years = pd.date_range('1/1/2000',
                      periods=2, freq=pd.DateOffset(years=1)).year                      
# Does not work
plt.figure()
plt.boxplot(data, positions=years)
# Works
plt.figure()
plt.boxplot(data, positions=years.values)
# Works
plt.figure()
plt.plot(years, data[0,:]) 

Actual outcome

Traceback (most recent call last):

  File "<ipython-input-38-2540b7c8b9eb>", line 6, in <module>
    plt.boxplot(data, positions=years)

  File "/Users/Ray/anaconda/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2729, in boxplot
    zorder=zorder, data=data)

  File "/Users/Ray/anaconda/lib/python3.6/site-packages/matplotlib/__init__.py", line 1717, in inner
    return func(ax, *args, **kwargs)

  File "/Users/Ray/anaconda/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 3378, in boxplot
    manage_xticks=manage_xticks, zorder=zorder)

  File "/Users/Ray/anaconda/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 3698, in bxp
    cap_x = np.array([cap_left, cap_right])

ValueError: setting an array element with a sequence.

Expected outcome

Expect to produce boxplot and label the xaxis '2000, 2001'
Unfortunately I cannot remember which version I previously used...

Matplotlib version

  • Operating system: macOS
  • Matplotlib version: 2.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: Python 3.6.3 :: Anaconda custom (x86_64)
  • Pandas version: 0.21.1

Installation

conda upgrade matplotlib

p.s. don't have much dev experience but happy to have a crack at this if it is desired.

Activity

  1. jklymak commented on Dec 16, 2017

    Member

    I think this is #9771. Pandas no longer registers their converter...

  2. raybellwaves commented on Dec 16, 2017

    Author

    Thanks. I wasn't aware of the change in pandas.
    It may be slightly different as it works for plot but not boxplot?
    I tried adding the

    from pandas.tseries import converter
    converter.register()
    

    to the top of my code but it didn't work. Am I missing something?

  3. jklymak commented on Dec 16, 2017

    Member

    Well, not sure what the problem is then. Sorry for the misdirect...

  4. jklymak commented on Dec 16, 2017

    Member

    But just to be sure, did you upgrade pandas at the same time? If so, I'd check if the change was on their end...

  5. raybellwaves commented on Dec 16, 2017

    Author

    Yeah, I think I upgraded a few packages at the same time. I'm using pandas: 0.21.1 (added this to my summary). I'll update if I find out more info

  6. modified the milestones: v2.1.2, on Dec 17, 2017
  7. tacaswell commented on Dec 17, 2017

    Member

    The issue is likely that Index objects used to act more like arrays than they do now or we are now using an array-like interface that Index does not support, or numpy is doing better and preserving types(would have to trace through the code to be sure of who broke who which is probably not worth doing).

    It looks like the exact issue is that

    # width
    if widths is None:
    widths = [np.clip(0.15 * np.ptp(positions), 0.15, 0.5)] * N
    elif np.isscalar(widths):
    widths = [widths] * N
    elif len(widths) != N:
    raise ValueError(datashape_message.format("widths"))
    is how we compute the box widths if position is passed in and we expect a list of floats, but for the Index types it is is returning a list of Index types (because np.ptp returns an Index type with one value in it). This makes sense for Index types in the context of pandas, but seems to be causing problems at the line the stack trace is on when we try to make an array out of the result of +/- operations on the Index object (which is still and Index object).

    Just passing this to float does not work (float blows up), adding in a call to np.asanyarray might do the trick though...

  8. added
    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …
    on Dec 17, 2017
  9. modified the milestones: needs sorting, v3.1 on Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL