Change colour order and restore it
294 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I want to change figure colour order. I use this
co = [0 0.4470 0.7410;
0.85 0.3250 0.098;
0.9290 0.6940 0.1250;
0.4940 0.1840 0.5560;
0.4660 0.6740 0.1880;
0.6350 0.0780 0.1840;
0.3010 0.7450 0.9330];
set(gca,'defaultAxesColorOrder',co)
get(gca,'colororder')
I only change the last row becuase I want this colour before. However, it does not work, I get this
ans =
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840
If I use this
co = [0 1 1;
0 0.5 0;
1 0 0;
0 0.75 0.75;
0.75 0 0.75;
0.75 0.75 0;
0.25 0.25 0.25];
Everything works fine... So, what is wrong?
On the other hand, after change the order (if I could), I want to restore it and I use this:
ax = gca; ax.ColorOrderIndex = 1;
But I could no restore it... I plot a figure and I get the same result that previously...
Any help?
Best regards
4 comentarios
Respuestas (3)
Stephen23
el 15 de Feb. de 2019
Editada: Stephen23
el 18 de Feb. de 2019
"I want to change figure colour order"
Figures do not have a ColorOrder property, only axes do.
It is easy to change the axes' ColorOrder, but note that "high-level" graphics operations (e.g. plot, surf, line, etc) completely reset the axes back to their default settings in preparation for displaying the new data. And the ColorOrder is not applied to already existing objects (i.e. you have to set the ColorOrder and then plot). This means there are basically two ways to set the ColorOrder:
- set the graphics root's default value to the colormap you want, or
- set an axes' value to the colormap you want AND also change its NextPlot value to 'replacechildren' or 'add'.
and then plot your new data.
Here is an example of the second option:
>> X = 0:0.1:2*pi;
>> Y = bsxfun(@plus,sin(X),(1:7).');
>> plot(X,Y,'LineWidth',3)
>> map = get(gca,'ColorOrder')
map =
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840
>> map([end-1,end],:) = map([end,end-1],:); % swap last two rows.
>> set(gca, 'ColorOrder',map, 'NextPlot','ReplaceChildren')
>> plot(X,Y,'LineWidth',3)
Looking at the first two lines it is clear that they have swapped color. And checking:
>> get(gca,'ColorOrder')
ans =
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.6350 0.0780 0.1840
0.3010 0.7450 0.9330
Afterwards you can reset the ColorOrder using:
set(gca,'ColorOrder','factory')
0 comentarios
Asieh Daneshi
el 16 de Feb. de 2019
write the following codes before plotting your resluts:
co = [0 0.4470 0.7410;
0.85 0.3250 0.098;
0.9290 0.6940 0.1250;
0.4940 0.1840 0.5560;
0.4660 0.6740 0.1880;
0.6350 0.0780 0.1840;
0.3010 0.7450 0.9330];
fig=figure;
set(fig,'defaultAxesColorOrder',co)
it worked for me. just adhere to the order of the codes.
Image Analyst
el 16 de Feb. de 2019
You can save the default color order in advance if you want to change it and restore it. See my attached demo (which sets it but does not restore it though that is trivial)
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!