1

I have dictionary containing 9 dataframes. I want to create a 3,3 subplot and plot bar charts for each dataframe.

To plot a single plot I would do this (just a singplot not considering subplots),

%matplotlib inline
with plt.style.context('bmh'):
    famd = satFAMD_obj['MODIS.NDVI']
    df_norm = satFAMD_dfNorm['MODIS.NDVI']
    df_cor =famd.column_correlations(df_norm)
    df_cor.columns = ['component 1','component 2', 'component 3']
    df_cor.plot(kind = 'bar',cmap = 'Set1', figsize = (10,6))
plt.show()

where satFAMD_obj & satFAMD_dfNorm are two dictionaries containing factor analysis trained objects and a dataframes. In the next line I create a new dataframe called df_cor and then plot it using this line df_cor.plot(kind = 'bar',cmap = 'Set1', figsize = (10,6)).

Now my problem is when it comes to multiple subplots how do I do this ? I cannot simply do this,

fig,ax = plt.subplots(3,3, figsize = (12,8))
ax[0,0].df_cor.plot(kind = 'bar',cmap = 'Set1')

Any ideas?

1 Answer 1

1

I'm supposing that all of your keys in your two dictionaries will need to be plotted.

You will:

  • declare subplots,
  • iterate over dictionaries,
  • iterate over the axes objects,
  • plot to each set of axes.

Using code like the below example:

fig,ax = plt.subplots(3,3, figsize = (12,8))

for k1,k2 in zip(satFAMD_obj.keys(),satFAMD_dfNorm.keys()):
    for axes in ax.flatten():
        famd = satFAMD_obj[k1]
        df_norm = satFAMD_dfNorm[k2]
        df_cor = famd.column_correlations(df_norm)
        df_cor.columns = ['component 1','component 2', 'component 3']
        df_cor.plot(kind = 'bar',cmap = 'Set1',ax=axes)
        #                                      ^^^^^^^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.