I have following small data:
Tom Dick Harry Jack
Sub
Maths 9 12 3 10
Science 16 40 1 10
English 12 11 4 15
French 17 15 2 15
Sports 23 19 3 15
I want to create a bar chart in black-white/gray colors for these data.
I can have such a figure with following code:
df.plot(kind='bar', colormap='gray')
plt.show()
However, the fourth bar (Jack's) is pure white and same as background. How can I avoid this problem of last bar being pure white?
Use the other colormaps or manually enter the color names. Alternatively you can change the background by using different style sheet such as ggplot,seabor or fivethirty eight.
colors=['darkgray','gray','dimgray','lightgray']
df.plot(kind='bar',color=colors )
plt.show()
df.plot(kind='bar',colormap=plt.cm.viridis )
plt.show()
Using the style sheets here: https://matplotlib.org/3.1.1/gallery/style_sheets/style_sheets_reference.html
plt.style.use('seaborn')#change the style sheets here
df.plot(kind='bar',colormap=plt.cm.gray)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.