0

I am trying to plot a bar plot, but it looks really bad.

plt.style.use('ggplot')
x = ['High School or Below', 'College', 'Bachelor', 'Master or Above']
y = [maleDataFrame["Education"].str.contains("High School or Below").sum(),
     maleDataFrame["Education"].str.contains("College").sum(),
     maleDataFrame["Education"].str.contains("Bachelor").sum(),
     maleDataFrame["Education"].str.contains("Master or Above").sum()]
x_pos = [i for i, _ in enumerate(x)]
plt.bar(x_pos, y, color=['blue','red','green','yellow'])
plt.xlabel("Type of Education")
plt.ylabel("Level of Education Male")
customTitle = ""
plt.title(customTitle)
plt.xticks(x_pos, x)

How can I fix this?

enter image description here

1 Answer 1

1

You can add back the line that defines y to reproduce it using the data you have. Protip: Use bar(x, y, width=30) to modify the width of the bar as per your requirement.

Modified your code to:

plt.style.use('ggplot')
x = ['High School \nor Below', 'College', 'Bachelor', 'Master or \nAbove']
y = [10, 20, 30, 40]

plt.bar(x, y, color=['blue','red','green','yellow'])
plt.xlabel("Type of Education")
plt.ylabel("Level of Education Male")
customTitle = ""
plt.title(customTitle)

To give:

Example plot

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.