Home > Enterprise >  How to plot bar chart with python?
How to plot bar chart with python?

Time:04-23

I want to visualize a bar plot with 2 classes. Class=0 its color blue and class=1 its color red.

#here its my code
x = ['0','1']
real = df[df['fake'] == 0].count()
fake = df[df['fake'] == 1].count()
plt.bar(x, real, color='blue')
plt.bar(x, fake, color='red')
plt.title("Class Fake & Real")
plt.show() 

Error code : ValueError: shape mismatch: objects cannot be broadcast to a single shape

CodePudding user response:

from matplotlib import pyplot as plt
x = ['0', '1']
real, fake = 5, 10
plt.bar(x[0], real, color='blue')
plt.bar(x[1], fake, color='red')
plt.title("Class Fake & Real")
plt.show()

enter image description here

Your error may comes from wrong types of real and fake. BTW, for configuring different colors for bars, there is a better enter image description here

  • Related