-1

I am trying to chart two subplots, one under the other, using stacked bar charts. I can generate stacked bar charts and subplots, but am unable to combine the two, one underneath the other. Does anybody know of some code that I can look at that does not use pandas. I have been unable to install pandas, only numpy and matplotlib.

Thanks in advance.

Bob
  • 15
  • 1
  • 4
  • 1
    The [matplotlib documentation](https://matplotlib.org/gallery/index.html) has multiple examples for stacked bars or subplots. What is your specific problem adapting those scripts? As for your question - telling us that your input is not a pandas dataframe is not sufficient. Please provide a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Mr. T Aug 01 '18 at 07:31

1 Answers1

2
import numpy as np
import matplotlib.pyplot as plt


N = 5
menMeans = (20, 35, 30, 35, 27)
womenMeans = (25, 32, 34, 20, 25)
menStd = (2, 3, 4, 1, 2)
womenStd = (3, 5, 2, 3, 3)
ind = np.arange(N)    # the x locations for the groups
width = 0.35       # the width of the bars: can also be len(x) sequence


fig,axes = plt.subplots(nrows = 2)
fig.subplots_adjust(hspace=0.5, wspace=0.3)

for i,ax in enumerate(axes.flat):
  ax.bar(ind, menMeans, width, yerr=menStd)
  ax.bar(ind, womenMeans, width,
               bottom=menMeans, yerr=womenStd)

  ax.set_title('Scores by group and gender')
  ax.set_xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
  ax.set_yticks(np.arange(0, 81, 10))
  ax.legend((p1[0], p2[0]), ('Men', 'Women'))

plt.show()

Output:

enter image description here

Krishna
  • 6,107
  • 2
  • 40
  • 43
  • Thanks krishna. I am still having trouble getting this to provide two different charts. I modified the code to: – Bob Aug 01 '18 at 07:06
  • @Bob Can you tell what kind of graph you're looking for? Or what modification you'd like in current graph? – Krishna Aug 01 '18 at 07:26