python - Subplots from two DataFrames in one column, sharing x -axis -


i need plot few columns (two or more columns per 1 plot) 2 dataframes in 1 column,sharing x -axis. data has same index.
example taken , modified [1]:

 df = dataframe(randn(1000, 4), index=date_range('1/1/2000', periods=1000), columns=list('ab'))  df2 = dataframe(randn(1000, 4), index=df.index, columns=list('cd'))  df = df.cumsum()  df2 = df.cumsum()   fig, axes = plt.subplots(nrows=2, ncols=1, sharex=true)  df['a'].plot(ax=axes[0,0])  df2['c'].plot(ax=axes[0,0])  df['b'].plot(ax=axes[1,0])  df2['d'].plot(ax=axes[1,0]) 

running got: indexerror: many indices bug or missing ?

when change ncols=2,everything ok, 2 additional blank plots.

i can use other solution above looks better:

ax1 = subplot(211) df['a'].plot() df2['c'].plot()  ax2 = subplot(212, sharex=ax1) df['b'].plot() df2['d'].plot() 

it's because axes 1d ndarray axes[0, 0] not valid index. 0 , 1 valid. change plotting code to:

df['a'].plot(ax=axes[0]) df2['c'].plot(ax=axes[0]) df['b'].plot(ax=axes[1]) df2['d'].plot(ax=axes[1]) 

you do

fig, (ax1, ax2) = subplots(2, 1, sharex=true)  df['a'].plot(ax=ax1) df2['c'].plot(ax=ax1) df['b'].plot(ax=ax2) df2['d'].plot(ax=ax2) 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -