How to change color from a .fig file having subplots
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Emanuele Rondanina
le 31 Août 2017
Modifié(e) : Adam
le 31 Août 2017
I'm creating a function which takes as input a .fig file and it modifies its properties following a standard that I defined.
I would like to add an option to change the color of the plots according to a color order that I defined. If the figure has only one plot it's easy, I can modify the color property of each Line found with findobj, but I'm stuck with the figures having subplots.
I was thinking to use the ColorOrder option taken from the axes properties but the figure does not 'refresh' with the new colors (I tried also to use refresh( ... ) ).
Another idea I had was to modify the color Line by Line but I'm not able to distinguish to which subplot they belong (in theory every subplot should restart the color order).
Here is an idea of the outcome where on the left there is subplot(121) not yet modified while in subplot(122) there is the plot with the new color order. At the end subplot(121) and subplot(122) should have the same colors.
3 commentaires
Adam
le 31 Août 2017
Modifié(e) : Adam
le 31 Août 2017
The axes properties do strictly relate to the axes, but since one of those is 'Children', this contains the objects that are parented by the axes (whether they be lines, images, scatter plots, etc) so they when you retrieve them they can be interrogated themselves.
doc inspect
is an excellent tool for playing around with graphics objects and seeing more visually what you can access and how changing them affects the figure.
e.g.
inspect( hAxes )
will show you the axes properties in a dialog where they are easily editable. The end effect is no different to changing them programatically, but it is often faster when you just want to look around at what can be changed and what its effect is.
Réponse acceptée
José-Luis
le 31 Août 2017
Modifié(e) : José-Luis
le 31 Août 2017
Creating figure and forgetting all handles:
for ii = 1:2
subplot(1,2,ii);
plot(1:10,sort(rand(10)));
end
savefig('dummy')
close all
Loading figure:
fH = openfig('dummy.fig');
colorArray = eye(3);
numColors = size(colorArray,1);
%Getting axes objects
aH = findall(fH,'Type','axes').';
for ii = aH
lH = findall(ii,'Type','line').';
cnt = 0;
for jj = lH
idx = mod(cnt,numColors) + 1;
jj.Color = colorArray(idx,:);
jj.LineWidth = 2;
cnt = cnt + 1;
end
end
Your mileage may vary. Off the top of my head, it will not work if there are lines that are not visible. You'd need to adapt for that.
If you are not loading a figure but generating it, keeping track of your handles is the sane solution.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Object Properties dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!