0
votes

I'm having trouble creating a bar plot in Python. I'm trying to represent gender in a bar plot. There are 3 variables, male, female and unknown. The values originally came from a data frame in which I added a row which calculates the totals of each column. The totals row contains:

Male       2216732.0
Female     2856302.0
Unknown       8354.0

I am then plotting this totals row. I have the following:

demo_gender.iloc[211].plot(kind="bar",color=['cyan', 'magenta', 'red'],alpha=0.8) #barchart of final row of data frame
plt.xlabel('Gender') #x-axis label
plt.title('Bar chart of gender',fontsize=12) #title
plt.gcf().axes[0].yaxis.get_major_formatter().set_scientific(False) #get rid of scientific notation

When I run the above code a bar plot is produced. However it is only displaying bars for male and female but not for unknown even though there is a label and space for it created on the plot.

I am wondering is it not displaying because the value for unknown is so low compared to male and female? And if so is there a way to make it display it? I've included a copy of the barplot I'm getting atm.

enter image description here

1
Please include all your code. - Ann Zen
A log scale might be appropriate here... 8354 is too small relative to the other bars. - BigBen

1 Answers

0
votes

Your first guess is correct:

if I increase the unknown number to 835400:

enter image description here