How can I set a color gradient on my bar plot?
Show older comments
Hello!
I have the following vector of values:
[1 2 3 4 5 6 7 8 9 10; -1.8 -1.7 -1.3 -1.4 -1.8 -1.7 -1.6 -1.7 -1.5 -1.4].
The first line corresponds to the x-axis whereas the second is the y-axis. I would like to plot these values in a 2D bar plot with a color gradient. I would like to color the bars according to their height in order to highlight the maximum value (-1.3). How can I do that?
Many thanks in advance!
Accepted Answer
More Answers (1)
lisette
on 8 Aug 2016
0 votes
3 Comments
Robert
on 9 Aug 2016
What version of MATLAB are you using?
What you see there is similar to what I see after the figure updates and before I run
hBar.Face.StripData = [];
hBar.Face.VertexIndices = vi;
to re-apply the colors.
To get the colors you want, check out the other colormap options. hot and autumn are pretty close to what you described.
I like this method of coloring the bars because it doesn't affect the way you interact with the barseries object (except for the colors of course); however, you might find it easier to try the first approach and call bar once for each bar on your plot and give each their own color that way.
lisette
on 10 Aug 2016
lisette
on 10 Aug 2016
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!