0

The following code shows a bar in each x-axis value (4 bars in total):

import numpy as np
import matplotlib.pyplot as plt

n = 4
width = 0.35
china = (16,21,23,15) 
malaysia = (21,11,21,10)
x = np.arange(n)
p1 = plt.bar(x, malaysia, width, color='b')
p2 = plt.bar(x, china, width, color='r', bottom=malaysia)
plt.xticks(x, ('Round 1', 'Round 2', 'Round 3', 'Round 4'))
plt.ylabel('Points')
plt.title('China v/s Malaysia')
plt.yticks(np.arange(0, 60, 5))
plt.legend((p2[0], p1[0]), ('China', 'Malaysia'))
plt.show()

Similar Bar chart

I am looking to put 3-grouped bars instead of one (same as shown in: 3-Columns bar chart) but for each bar it should contain 2 parts (red and blue) as shown in 1st picture.

Thank you so much

David29
  • 21
  • 4
  • You need to combine a [stacked bar chart](https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html) with a [grouped bar chart](https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html). – ImportanceOfBeingErnest Mar 31 '19 at 15:55
  • Thank you @ImportanceOfBeingErnest, but I no know how to code that, I mean how to combine them – David29 Mar 31 '19 at 16:46
  • I found a similar code (of @Meher Béjaoui) in this link: [https://stackoverflow.com/questions/47205918/plot-multiple-stacked-bar-in-the-same-figure] but I want to add another bar to each one, and specify only two colors for all bars – David29 Mar 31 '19 at 21:13

0 Answers0