1
$\begingroup$

In pandas I can set the date as index, and then run df.plot() to see a line chart. How do I make that line chart stacked as in the picture below?

enter image description here

$\endgroup$
  • $\begingroup$ Add your sample df $\endgroup$ – Aditya Apr 18 '18 at 12:49
4
$\begingroup$

You can simply use

df.plot.area()

Found on https://python-graph-gallery.com/254-pandas-stacked-area-chart/ after a quick google search.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Np. The keyword you may have left out was “area”, but honestly I’m not sure how I remembered that’s what these plots are called. $\endgroup$ – kbrose Apr 18 '18 at 13:51
  • $\begingroup$ Do you know how I would do if I would add a group D to that plot from python-graph-gallery, and group D should not be stacked i.e. just a regular line? $\endgroup$ – jacob Apr 18 '18 at 14:00
  • $\begingroup$ df.plot.area() returns the matplotlib axis object, just call ax.plot(my_data) $\endgroup$ – kbrose Apr 18 '18 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.