Cara plot grouped bar chart berlabel pada Python menggunakan Matplotlib

Admin
0
Berikut adalah kodingan dasar untuk mem-plot grouped bar chart berlabel pada Python menggunakan Matplotlib dan hasilnya akan seperti gambar berikut :





import matplotlib.pyplot as plt
import numpy as np


labels = ['2001', '2002', '2003', '2004', '2005']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

x = np.arange(len(labels))  
width = 0.35 

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Pria')
rects2 = ax.bar(x + width/2, women_means, width, label='Wanita')

ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
ax.legend()

ax.bar_label(rects1, padding=3)
ax.bar_label(rects2, padding=3)

fig.tight_layout()

plt.show()

Post a Comment

0Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)

Disclaimer : Content provided on this page is for general informational purposes only. We make no representation or warranty of any kind, express or implied, regarding the accuracy, adequacy, validity, reliability, availability or completeness of any information.

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top