Skip to content

boxplot: positions used to take Int64Index #10022

Closed
@raybellwaves

Description

@raybellwaves

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

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions