1

I have two lists:

list1 = ['100', '50', '25']
list2 = ['0', '50', '75']

They equal to 100 at their index.

Trying to create a stacked bar plot, and the x and y axis can be the list variable name, list1, and list2.

I've been toying with this for a while but have little experience with python and pandas. Any help is appreciated.

Grayrigel
  • 3,474
  • 5
  • 14
  • 32
ec1985
  • 11
  • 1
  • 1
    **They equal to 100 at their index.** what does it mean? can you clarify? – Grayrigel Oct 24 '20 at 00:05
  • Can you clarify your desired output? – Scott Boston Oct 24 '20 at 00:18
  • Please se: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples on how to create a pandas minimum reproducible example. You are missing some important information including data you would use as the variable that is stacked. – David Erickson Oct 24 '20 at 01:53
  • @Grayrigel list1[0] + list2[0] = 100 and so on... – ec1985 Oct 24 '20 at 03:39
  • @ScottBoston i would like to show 3 bars, the first one would show list1[0] at 100%, list2[0] would be 0 so nothing would be plotted for list2.... list1[1] would show a bar with 50 and another bar for list2[1] with 50, and lastly, a third bard with list1[2] showing 25 and list2[2] showing 75. so basicallly 3 bars that equal to 100... – ec1985 Oct 24 '20 at 03:41
  • https://ibb.co/JHpP3w2 this is a very poor job of what im trying to do – ec1985 Oct 24 '20 at 03:49

1 Answers1

0

Try this:

import pandas as pd
import matplotlib.pyplot as plt

list1 = ['100', '50', '25']
list2 = ['0', '50', '75']

df = pd.DataFrame({'list1':list1,
                  'list2':list2})

df = df.astype(int)
df.plot.bar(stacked=True)

Output:

enter image description here

Scott Boston
  • 147,308
  • 15
  • 139
  • 187