Skip to content
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

Feature request: hierarchical axes labels on bar charts #2088

Closed
gjx opened this issue Oct 20, 2012 · 2 comments
Closed

Feature request: hierarchical axes labels on bar charts #2088

gjx opened this issue Oct 20, 2012 · 2 comments

Comments

@gjx
Copy link

gjx commented Oct 20, 2012

Related to matplotlib/matplotlib#1257.

This is a feature available in Excel and OpenOffice 3.3.

Example:
http://i.imgur.com/8SjMs.png

I think there may be a simple way to do it with matplotlib's table to construct the hierarchical axes labels. I'm not an expert in matplotlib or pandas, but I've cobbled together a small demo:

import itertools

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

row_labels = itertools.product(['ASub', 'DSub'], ['LD', 'LS'], ['GD', 'GS'],
                               ['Attn', 'Dist'])
midx = pd.MultiIndex.from_tuples([row for row in row_labels],
                                 names=['Group', 'Local', 'Global', 'Attn'])
df = pd.DataFrame({'mean': np.random.rand(16)}, index=midx)

ax = df.plot(kind='bar')
ax.xaxis.set_visible(False)

cell_text = np.array(df.index.tolist()).T
ax.table(cellText=cell_text, rowLabels=df.index.names, cellLoc = 'center')

plt.subplots_adjust(bottom=0.2)
plt.show()

Produces the plot
http://i.imgur.com/OB8wi.png

There's probably a smarter way to populate the table in order to place the labels at the center of the merged cells as well as fix the spacing clashes.

@ghost ghost mentioned this issue Dec 12, 2012
@petehuang
Copy link
Contributor

This issue's last interaction was 4 years ago. As far as I can tell, the functionality is still unsupported, with latest activity in Summer 2016 (matplotlib/matplotlib#6321).

@mroeschke mroeschke removed this from the Someday milestone Oct 13, 2022
@MarcoGorelli
Copy link
Member

there's been no activity here for > 10 years - closing then, but thanks for the suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants