0

I am trying to put two types of plot in one figure like below:

fig, axes = plt.subplots(25, 1, figsize=(8, 32), sharex=True, sharey=False)

names = my_df['person'].values.tolist()

for i in range(len(names)):
    :
    :
    ax = my_df.plot(x='timestamp', y='col_A', kind='bar',  color = 'b', \
           alpha = 0.7, ax=axes[i])
    my_df.plot(x='timestamp', y='col_A', kind='bar',  color = 'b', alpha = 0.5, ax=axes[i])
    my_df.plot(x='timestamp', y='col_B',  color = 'r', alpha = 0.5, ax=axes[i])

The figure works fine if I just plot one of them. I.e.

my_df.plot(x='timestamp', y='col_A', kind='bar',  color = 'b', alpha = 0.5, ax=axes[i])

works fine by itself.

my_df.plot(x='timestamp', y='col_B',  color = 'r', alpha = 0.5, ax=axes[i])

also works fine by itself.

However, these two plots could not show together on the same figure. I am guessing my axes wasn't defined properly? Is there a way to fix it? Thanks!

Edamame
  • 23,718
  • 73
  • 186
  • 320
  • Can you show how you instantiate the axes and the create your variable `axes`? – saintsfan342000 Aug 23 '17 at 16:14
  • While it may well be that [the duplicate](https://stackoverflow.com/questions/23482201/plot-pandas-dataframe-as-bar-and-line-on-the-same-one-chart) or other questions like [this](https://stackoverflow.com/questions/39560099/cannot-combine-bar-and-line-plot-using-pandas-plot-function) or [this](https://stackoverflow.com/questions/22623324/plot-bar-graph-and-timeseries-plot-on-different-axis-using-pandas?noredirect=1&lq=1) don't help you, it will be necessary to explicitely state in how far they don't give you the desired result and to provide a [mcve] of the issue. – ImportanceOfBeingErnest Aug 23 '17 at 16:28
  • Hi, I have added the axes definition above. I looked into the other question: Plot Pandas DataFrame as Bar and Line on the same one chart , but couldn't apply it to my case ... – Edamame Aug 23 '17 at 17:06
  • The example code above is not a [mcve]. If you have problem applying a solution, you need to state what the problem actually is. – ImportanceOfBeingErnest Aug 23 '17 at 18:09

0 Answers0