Skip to content

Commit 1e39ad9

Browse files
committed
ENH: Raise UserWarning only if redrawing on existing axis with data
1 parent a28db9c commit 1e39ad9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

doc/source/user_guide/visualization.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,6 @@ Asymmetrical error bars are also supported, however raw error values must be pro
14321432
Here is an example of one way to easily plot group means with standard deviations from the raw data.
14331433

14341434
.. ipython:: python
1435-
:okwarning:
14361435
14371436
# Generate the data
14381437
ix3 = pd.MultiIndex.from_arrays([

pandas/plotting/_matplotlib/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,12 @@ def __init__(self, data, **kwargs):
13561356
self.lim_offset = 0
13571357

13581358
if isinstance(self.data.index, ABCMultiIndex):
1359-
# No real handling for MultiIndex yet
1360-
warnings.warn(
1361-
"Bar plot with a MultiIndex is not supported.", UserWarning,
1362-
)
1359+
if kwargs["ax"] is not None and kwargs["ax"].has_data():
1360+
warnings.warn(
1361+
"Redrawing a bar plot with a MultiIndex is not supported "
1362+
+ "and may lead to inconsistent label positions.",
1363+
UserWarning,
1364+
)
13631365
self.ax_index = np.arange(len(data))
13641366
else:
13651367
self.ax_index = self.data.index

pandas/tests/plotting/test_frame.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,9 +3509,11 @@ def test_bar_multiindex(self):
35093509
errors = gp3.std()
35103510

35113511
# No assertion we just ensure that we can plot a MultiIndex bar plot
3512-
# and are getting a UserWarning
3512+
# and are getting a UserWarning if redrawing
3513+
with tm.assert_produces_warning(None):
3514+
ax = means.plot.bar(yerr=errors, capsize=4)
35133515
with tm.assert_produces_warning(UserWarning):
3514-
means.plot.bar(yerr=errors, capsize=4)
3516+
means.plot.bar(yerr=errors, capsize=4, ax=ax)
35153517

35163518

35173519
def _generate_4_axes_via_gridspec():

0 commit comments

Comments
 (0)