2

Below sample data is not the exact data which I am using, it is just a data with random values.

Sample data:

Region x y
India 25 12
Australia 18 05
USA 77 56
Ghana 28 13
France 35 41
UK 50 72
Germany 44 12
Spain 10 16
Russia 09 91

I want to create a bar plot comparing x and y columns of each region. And bar for x and y should be displayed side by side.

Code I used

plt.bar('Region', 'State_Fund_Accrual2016', data = df, color = 'green', label = "State fund Planned", alpha = 0.5)
plt.bar('Region', 'State_Fund_Release2016', data = df, color = 'red', label = "State fund Released", alpha = 0.5
plt.legend()
plt.xticks(rotation = 90, fontsize = 10)

plt.show

Below is the output which I am getting

enter image description here

Desired output:

I want my plot to look similar to the below image enter image description here

Please suggest some method to get the desired output

  • 1
    Does this answer your question? [How to plot bar graphs with same X coordinates side by side ('dodged')](https://stackoverflow.com/questions/10369681/how-to-plot-bar-graphs-with-same-x-coordinates-side-by-side-dodged) – IoaTzimas Jul 21 '21 at 11:03
  • 1
    Beside @IoaTzimas comment you can also find a similar answer if you are using `np.array` [here](https://stackoverflow.com/questions/68357753/how-do-i-convert-csv-data-into-bar-chart/68358263#68358263). But it seems like you're using DataFrame, in that case @tdy answer should do the work – QuagTeX Jul 21 '21 at 11:12

1 Answers1

3

In this case it would be simplest to use DataFrame.plot.bar() with Region as the index:

df.set_index('Region').plot.bar()

multibar output

tdy
  • 36,675
  • 19
  • 86
  • 83