3

I am plotting 4 subplots as follows:

def plot_bar(corr_df):

    dfstacked = corr_df.stack().order()
    dfstacked.plot(kind='bar', rot=60)

def plot_heatmap(corr_df):

    corr_df = corr_df.fillna(value=0)
    plt.pcolormesh(corr_df.values, cmap=plt.cm.Blues)
    plt.yticks(np.arange(0.5, len(corr_df.index), 1), corr_df.index)
    plt.xticks(np.arange(0.5, len(corr_df.columns), 1), corr_df.columns)

plt.subplot2grid((2,5), (0,0), colspan=3)
plot_bar(df)

plt.subplot2grid((2,5), (0,3), colspan=2)
plot_heatmap(df)

plt.subplot2grid((2,5), (1,0), colspan=3)
plot_bar(df)

plt.subplot2grid((2,5), (1,3), colspan=2)
plot_heatmap(df)

plt.tight_layout()
plt.show()

plot

The plot is created correctly, however the x-axis labels are missing on one of the bar charts on the left hand side. The labels are always missing from whichever bar chart is plotted 1st out of the 2 bar charts.

So if I plot the bar chart in position 0,0 first then that is the one which will have no x-axis labels. If I plot the chart in position 1,0 first, then that one will be missing the labels.

I presume it has something to do with the fact that the labels are quite long and are getting cut off by the bar chart plotted 2nd,...but im not sure.

EDIT:

Here's the dataframe example. Just set_index to symbol:

symbol     aaa       bbb      ccc     ddd      eee     fff      ggg
aaa                         
bbb       -0.001                        
ccc        0.348    -0.025                  
ddd       -0.42     -0.075   -0.701             
eee       -0.276     0.004   -0.516   0.661         
fff        0.175    -0.107    0.363  -0.521   -0.356        
ggg        0.469     0.012    0.364  -0.519   -0.306    0.306   
darkpool
  • 13,822
  • 16
  • 54
  • 89
  • 1
    Can you give a copy-pastable example of `df`? – Lee Nov 23 '15 at 13:32
  • http://stackoverflow.com/questions/33869234/creating-a-subplot-instead-of-separate-plots – Lee Nov 23 '15 at 13:36
  • Thanks. Posted example dataframe. Any idea what is going on? It's fine plotting one bar chart and one matrix. The problem is the missing labels when plotting 4 charts. – darkpool Nov 23 '15 at 14:03
  • 4
    Can you try this... First assign the first plot to a variable named ax... ax =plt.subplot2grid((2,5), (0,0), colspan=3) then add below line at the end before plt.show() .... plt.setp(ax.get_xticklabels(), visible=True) – Shahram Nov 23 '15 at 21:01
  • 1
    Thanks @Shahram that did the trick. I wonder why that is needed? It's a bit annoying having to do that only on whichever plot is plotted first. Anyway, it's working. Thanks. – darkpool Nov 24 '15 at 06:53

0 Answers0