8000 Inconsistent indexes for tick label plotting by nrebena · Pull Request #28733 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Inconsistent indexes for tick label plotting #28733

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

Merged
merged 19 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Add UserWarning when plotting bar plot with MultiIndex
  • Loading branch information
nrebena committed Sep 12, 2020
commit 3c8b54fa3d7700a9e2534615fd4cded4b71326ee
1 change: 1 addition & 0 deletions doc/source/user_guide/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ Asymmetrical error bars are also supported, however raw error values must be pro
Here is an example of one way to easily plot group means with standard deviations from the raw data.

.. ipython:: python
:okwarning:

# Generate the data
ix3 = pd.MultiIndex.from_arrays([
Expand Down
3 changes: 3 additions & 0 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,9 @@ def __init__(self, data, **kwargs):

if isinstance(self.data.index, ABCMultiIndex):
# No real handling for MultiIndex yet
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we hit this in tests? why are we not just raising?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good remark. The real behavior that we want to warn against is redrawing a MultiIndex on a existing axis with data. I change the code and the test accordingly, so that drawing a Bar Plot with a MultiIndex does not warn (it is supported, and documented), but that redrawing is not (that is the original bug issue, where reordering the data and replotting on the same axis lead to inconsistent labels.)

"Bar plot with a MultiIndex is not supported.", UserWarning,
)
self.ax_index = np.arange(len(data))
else:
self.ax_index = self.data.index
Expand Down
0