0

I want to combine these two charts from a DataFrame: two charts into one so that they are stacked on top of each other.

The only thing I obtain with this code:

plt.style.use('ggplot')
fig, ax = plt.subplots(sharey=True)

hw = hotwater_qa_1day.plot(kind='bar',stacked=True,width=1,colormap='autumn',figsize=(20,5),ax=ax)
ht = heatdemand_qa_1day.plot(kind='bar',stacked=True,width=1,colormap='winter',figsize=(20,5),ax=ax)
plt.ylabel('Heatdemand and Hotwater')
plt.xlabel('Time')
plt.title('Title')
plt.show()

is the chart where one part of data hides the other. Like here: faulty chart

How to solve it? I want them to be on one plot. Not on two subplots.

Ola.Rad
  • 23
  • 3
  • Use two subplots. – Stop harming Monica Jan 30 '19 at 14:05
  • Use `fig, (ax1, ax2) = plt.subplots(2, 1, sharey=True)` and then pass ax1 to the first and ax2 to the second – Sheldore Jan 30 '19 at 14:08
  • Possible duplicate of [How do I get multiple subplots in matplotlib?](https://stackoverflow.com/questions/31726643/how-do-i-get-multiple-subplots-in-matplotlib) – Sheldore Jan 30 '19 at 14:13
  • The stacking is performed internally in the plot command. So to achieve a stacked plot that includes the data from both datasets, you will first need to combine the two datasets into one. Then plot a stacked bar plot of the single dataset. The problem will be to get the categories right and apply the colors correctly. Admittedly this will not be easy, but if you share a [mcve] someone may tackle this problem and help you out. – ImportanceOfBeingErnest Jan 30 '19 at 14:16

0 Answers0