Repository navigation
Closed
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …third-party integration
Milestone
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.
Metadata
Metadata
Assignees
Labels
API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …Consistency of the matplotlib API, including naming, behavior, defaults, …third-party integration
Activity
jklymak commentedon Dec 16, 2017
I think this is #9771. Pandas no longer registers their converter...
raybellwaves commentedon Dec 16, 2017
Thanks. I wasn't aware of the change in pandas.
It may be slightly different as it works for
plotbut notboxplot?I tried adding the
to the top of my code but it didn't work. Am I missing something?
jklymak commentedon Dec 16, 2017
Well, not sure what the problem is then. Sorry for the misdirect...
jklymak commentedon Dec 16, 2017
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...
raybellwaves commentedon Dec 16, 2017
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
tacaswell commentedon Dec 17, 2017
The issue is likely that
Indexobjects used to act more like arrays than they do now or we are now using an array-like interface thatIndexdoes 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
matplotlib/lib/matplotlib/axes/_axes.py
Lines 3680 to 3686 in 7a6bab7
Indextypes it is is returning a list ofIndextypes (becausenp.ptpreturns anIndextype with one value in it). This makes sense forIndextypes 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 theIndexobject (which is still andIndexobject).Just passing this to
floatdoes not work (float blows up), adding in a call tonp.asanyarraymight do the trick though...