Home > Back-end >  Plotting multi-indexed data with subplots only at one level
Plotting multi-indexed data with subplots only at one level

Time:02-02

Edit with example data in code format:

import pandas as pd

data = {'Station':  ['station 1', 'station 1', 'station 1', 'station 1','station 2', 'station 2','station 2', 'station 2', 'station 2', 'station 2'],
        'month': ['March', 'Arpil', 'March', 'Arpil','March', 'Arpil','March', 'Arpil', 'March', 'Arpil'],
         'x1': ['22', '42', '11', '56','28', '33','87', '34', '11', '25'],
      'x2': ['52', '47', '31', '52','38', '35','47', '54', '10', '45']
        }

df = pd.DataFrame(data)

df = df.groupby(['Station','month']).mean()

df.transpose().plot(subplots=True, kind='bar')

I am unable to get separate subplots for station, a cluster of bars in each subplot for category (e.g, x1), and each cluster representing one month (see Excel graph for representative subplot).

I have a dataframe (that I've converted to excel for the purpose of asking this question) that is organized in the following way:

DF format

I'm looking to generate subplots at the station level that have clustered bars for every quality (X2, X2..etc.) month to month. I don't think I'm doing a great job of describing that, so I created an example subplot in Excel.

Example of one subplot.

I would ideally have a subplot that looked like that for every station. I have figured out how to generate a sub plot for each station, but I can't figure out how to integrate the time element (and the clustered bars).

CodePudding user response:

I don't think pandas convenience wrapper for matplotlib natively supports grouped bar charts in subplots. The enter image description here

The enter image description here

  •  Tags:  
  • Related