python - Building a stacked bar chart from a list within a dictionary matplotlib -


i have dictionary contains list each value, example:

countries = {'ng': [1405, 7392], 'in': [5862, 9426], 'gb': [11689, 11339], 'id': [7969, 2987]} 

is there way build stacked bar chart dictionary using each value bit of stack each key?

as in bar_stacked example matplotlib site, use bottom argument bar shift bars, 1 on top of other.

import matplotlib.pyplot plt import numpy np  countries = {'ng': [1405, 7392], 'in': [5862, 9426],               'gb': [11689, 11339], 'id': [7969, 2987]}  c = [] v = []              key, val in countries.items():     c.append(key)     v.append(val) v = np.array(v)  plt.bar(range(len(c)), v[:,0]) plt.bar(range(len(c)), v[:,1], bottom=v[:,0]) plt.xticks(range(len(c)), c) plt.show() 

enter image description here


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -