MATLAB Answers


How do I get a bar chart in the newest version but with the colors from an older version?

Asked by Stacy Sidle on 23 May 2019
Latest activity Commented on by Stacy Sidle on 23 May 2019
I am trying to regenerate a bar chart that was initially created using an older version of Matlab, but I am now using the 2019 version and the colors are completely different. I have not been able to locate a definitive answer to what the default colors are for a bar chart.


Stacy - perhaps show some of your code (in particular that which generates the bar chart). Also, show a screen shots (of the charts) contrasting the older version and 2019 version of MATLAB so that we can understand/see how the colours have changed.
Sample bar chart
A = [1:4;2:5;3:6;4:7];
h = bar(A);
Top plot is old colors (from Matlab 2016, I think), bottom is new version (2019). I know I can do a colorpicker kind of thing and set the RGB values manually, but on the old version of Matlab, which I still have on my work computer, I could do
and change the bars at will just by using a different colormap name, but that does not seem to be an option anymore.
Screen Shot 2019-05-22 at 9.32.05 PM.png
Screen Shot 2019-05-22 at 9.30.48 PM.png

Sign in to comment.


2 Answers

Answer by Stephen Cobeldick on 23 May 2019
Edited by Stephen Cobeldick on 23 May 2019
 Accepted Answer

"I have not been able to locate a definitive answer to what the default colors are for a bar chart."
The bar documentation states "Starting in R2017b, the default value is an RGB triplet from the ColorOrder property of the axes. In previous releases, the default value was 'flat' and the colors were based on the colormap", so clearly for version >=R2017b you will have to change the axes ColorOrder property rather than the figure/axes colormap.
Learn about the axes ColorOrder property by reading the documentation, e.g.:
Note that setting the axes ColorOrder is a little bit tricky as high-level plotting commands (e.g. plot, bar, etc.) reset most axes properties back to their defaults. You could change the default ColorOrder or change the axes NextPlot property to ReplaceChildren so that these properties are not reset.
For some examples of how to change the axes ColorOrder property see my FEX submission:
Note that there is absolutely no need to poke around with external utilities to get the previously used colors: as the documentation makes clear, earlier versions used the figures/axes colormap colors, which are of course available by simply calling the appropriate colormap function (or even obtained from the saved .fig files). The default colormaps are:
  • <R2014b jet
  • >=R2014b parula
So you should try something like this:
ax = axes('ColorOrder',parula(7),'NextPlot','replacechildren');

  1 Comment

I need to look around a little more at the links you gave, but the code snippet you posted with parula(4) for my four bars solved the issue. Thanks!

Sign in to comment.

Answer by the cyclist
on 23 May 2019

There are utilities (e.g. "Digital Color Meter" on a Mac) where you can hover your cursor over a pixel on the screen, and it will report the RGB value of that pixel. Assuming you have a copy of the old figure on your computer, that would allow you to identify the exact colors, which you can then replicate in the new version of MATLAB.


Sign in to comment.