'Having a colorbar for a bar plot in python

Hi I don't know if this is possible, but I have made a bar plot in python where the color is a hex value. If I have the value that a hex code corresponds to, is it possible to make a colorbar for my bar plot in python? Or is there a way to use a colormap for bar plots in python?

This is my image right now. The color corresponds to a value, and I want to add a colorbar that has a range of colors with the value it will be. I have done this for scatter plots but I did not use a color map but just hex values for each bar.

example bar chart



Solution 1:[1]

Matplotlib does support colobars. Here's the API:

http://matplotlib.org/api/colorbar_api.html

Here's a code sample of a colorbar associated with a plot:

http://matplotlib.org/examples/pylab_examples/colorbar_tick_labelling_demo.html

EDIT:

Specifically to a bar plot, you could use a LinearSegmentedColormap instead of a colorbar, as in here

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