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

5 Ansichten (letzte 30 Tage)
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.
  2 Kommentare
Geoff Hayes
Geoff Hayes am 23 Mai 2019
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.
Stacy Sidle
Stacy Sidle am 23 Mai 2019
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
colormap(parula)
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 23 Mai 2019
Bearbeitet: Stephen23 am 23 Mai 2019
"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');
bar(ax,...)
  1 Kommentar
Stacy Sidle
Stacy Sidle am 23 Mai 2019
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

the cyclist
the cyclist am 23 Mai 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.

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by