Skip to content
Advertisement

How to add color gradients according to y-value to a bar plot?

Suppose I have a vertical bar plot like this:

Bar plot

MWE per this suggestion:

JavaScript

Is there an easy way to color the bars with a colormap according to the y-values they actually span (suppose my color bar goes from 1-12 where 1 is represented by yellow and 12 is represented by dark-blue)?
I have tried to adapt this example but wasn’t successful.

Advertisement

Answer

Here is the code in this post adapted such that each bar shows a corresponding slice of the gradient.

JavaScript

resulting plot

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement