Skip to content

Commit c1bce27

Browse files
committed
ENH: Raise UserWarning only if redrawing on existing axis with data
1 parent 8bd0842 commit c1bce27

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

doc/source/user_guide/visualization.rst

-1
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,6 @@ Asymmetrical error bars are also supported, however raw error values must be pro
14031403
Here is an example of one way to easily plot group means with standard deviations from the raw data.
14041404

14051405
.. ipython:: python
1406-
:okwarning:
14071406
14081407
# Generate the data
14091408
ix3 = pd.MultiIndex.from_arrays([

pandas/plotting/_matplotlib/core.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1331,10 +1331,12 @@ def __init__(self, data, **kwargs):
13311331
self.lim_offset = 0
13321332

13331333
if isinstance(self.data.index, ABCMultiIndex):
1334-
# No real handling for MultiIndex yet
1335-
warnings.warn(
1336-
"Bar plot with a MultiIndex is not supported.", UserWarning,
1337-
)
1334+
if kwargs["ax"] is not None and kwargs["ax"].has_data():
1335+
warnings.warn(
1336+
"Redrawing a bar plot with a MultiIndex is not supported "
1337+
+ "and may lead to inconsistent label positions.",
1338+
UserWarning,
1339+
)
13381340
self.ax_index = np.arange(len(data))
13391341
else:
13401342
self.ax_index = self.data.index

pandas/tests/plotting/test_frame.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3432,9 +3432,11 @@ def test_bar_multiindex(self):
34323432
errors = gp3.std()
34333433

34343434
# No assertion we just ensure that we can plot a MultiIndex bar plot
3435-
# and are getting a UserWarning
3435+
# and are getting a UserWarning if redrawing
3436+
with tm.assert_produces_warning(None):
3437+
ax = means.plot.bar(yerr=errors, capsize=4)
34363438
with tm.assert_produces_warning(UserWarning):
3437-
means.plot.bar(yerr=errors, capsize=4)
3439+
means.plot.bar(yerr=errors, capsize=4, ax=ax)
34383440

34393441

34403442
def _generate_4_axes_via_gridspec():

0 commit comments

Comments
 (0)