0

I can't figure out a way to put a colormap on my bar chart. I want the color to be a gradient from left to right. Thanks for any help/suggestions.

import matplotlib.pyplot as plt

sorted_dict = OrderedDict(sorted(accidents_by_road_user.items(), key = 
                 lambda kv:(kv[1], kv[0])))
roadkey = sorted_dict.keys()
roadvalue = sorted_dict.values() 

fig = plt.figure(dpi=100, figsize=(10,4))
plt.bar(roadkey, roadvalue)
plt.title('Distribution of Accidents by the Primary Road User', fontsize=12)
plt.ylabel('Number of Accidents', fontsize=9)
plt.xlabel('Type of Primary Road User', fontsize=9)
Keldorn
  • 1,980
  • 15
  • 25
  • Does this work? https://matplotlib.org/3.2.1/gallery/lines_bars_and_markers/gradient_bar.html – Keldorn Apr 17 '20 at 07:52
  • @Keldorn sorry if i didnt explain this well. I mean the left bar being a light shade of one colour and the right being a darker shade. – JamesParson121 Apr 17 '20 at 08:50
  • 1
    Does this answer your question? [vary the color of each bar in bargraph using particular value](https://stackoverflow.com/questions/18903750/vary-the-color-of-each-bar-in-bargraph-using-particular-value) – Keldorn Apr 17 '20 at 09:46

0 Answers0