Is it possible to hierarchically designate the line chart of matplotlib (pyplot)?

I managed to make the following bar graph using matplotlib.pyplot.

enter image description here

The plot comes from an aggregated PANDAS DataFrame printed below. Notice that each column in the line chart corresponds to a value in the mean column. Also note that the values ​​are not zero, but PANDAS outputs 0 and -0 when the floats are very small.

 Group Local Global Attn mean ASub LD GD Attn -0 Dist -0 GS Attn -0 Dist -0 LS GD Attn -0 Dist -0 GS Attn -0 Dist -0 DSub LD GD Attn -0 Dist 0 GS Attn -0 Dist -0 LS GD Attn -0 Dist -0 GS Attn -0 Dist -0 

I would like to mark the x axis of my column in hierarchical order, corresponding to the methods above. In other words, the left half of the x axis corresponds to the ASub group. The left half of the ASub group corresponds to the LD level of the Local factor, etc ...

Can this be done?

EDIT:

I think I should probably clarify what I want. I would like there to be a few shortcuts that go from most general (groups) to most specific (Attn), like the organization located to the left of the four columns of the DataFrame above.

+4
source share
1 answer

On the main thing this is implemented (I used random data for "mean"), see the image below. If you prefer not to update, you can also install it manually:

 In [143]: ax = df.plot(kind='bar') In [144]: ax.set_xticklabels(['|'.join(t) for t in df.index]) 

enter image description here

EDIT:

  In [167]: ax = df.plot(kind='bar') In [168]: ax.set_xticklabels(df.index.format(names=False)) 

enter image description here

+5
source

Source: https://habr.com/ru/post/1434231/


All Articles