-1

I need to get such result I have this now

How can I make all histogram rectangles in one color, make certain grid as on photo, and set words written on x-axis on vertical position as on example?

fig = plt.figure(figsize=(6,7))  
ax = fig.add_subplot()  
plt.title('Survived vs Sex')  
ax.bar('Female', survivedf/totalf)  
ax.bar('Male', survivedm/totalm)  
ax.set_xlabel('Sex')  
plt.legend('Survived')  
plt.show()
nathan liang
  • 1,000
  • 2
  • 11
  • 22
  • 1
    `ax.bar(..., color='royalblue')` to have blue bars. `ax.tick_params(axis='x', labelrotation=90)` to rotate the tick labels. – JohanC Mar 30 '22 at 20:47

1 Answers1

0

Call the bar function just once and pass a list/an array with all the values you want to plot. You don't have to call it for every single value you want to plot. Tick labels can be rotated with the rotation-argument of the plt.xticks function.

import matplotlib.pyplot as plt

plt.bar(['female', 'male'], [0.7, 0.2])
plt.xticks(rotation=90)

Or alternatively, use the object oriented interface:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(1) 

labels = ['female', 'male']
ax.bar(labels, [0.7, 0.2])
ax.set_xticklabels(labels, rotation=90)
Flursch
  • 483
  • 2
  • 4