'How to make all matplotlib histogram rectangles in one color and set words written on x-axis on vertical position? [duplicate]


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()
Solution 1:[1]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
