Matlab: list of overlay legends and legend overlapping graphics after saving

I am trying to reverse the order of the legend entries based on the reverse color order of the legends in the matte cap of the capital letters , but this does not seem to work in my case.

Basically, I have a GUIDE figure that draws a lot of plots and can save them in a .png file. The effect looks like this: http://i.imgbox.com/KzEFAdia.png

I managed to change the order of the text by turning the legend upside down, but I can’t change the order of the colors of the legends. Here is what I have:

[a b] = legend(legenda);

map = colormap; % current colormap

n = size(b,1);

z = linspace(size(map,1),1,n/3); % there is 1 text and 2 line elements for every data series, so I divide by 3

z = round(z); %otherwise matlab gets angry that indices must be real integers or logicals

MAP = map(z(:),:); % gets elements specified by linspace from colormap

So far, everything is working fine.

Vector b for two episodes looks like this (starts with 2.0 because it changed):

Text    (P+C 200 2.0.dpt)
Text    (P+C 200 1.0.dpt)
Line    (P+C 200 2.0.dpt)
Line    (P+C 200 2.0.dpt)
Line    (P+C 200 1.0.dpt)
Line    (P+C 200 1.0.dpt)

So, I realized (based on the linked code), I need to change the color variable for each row entry.

for k = (n/3 + 1):n
   a1 = get(b(k),'Children');
   set(a1,'FaceColor',MAP(ceil((k - n/3)/2), :));
end

Ceil and dividing by 2 gives the same index twice.

, , .

, , . MAP- - .

a1 =... for, :

a1 = 

  0x0 empty GraphicsPlaceholder array.

?

, (. , )?

, , - "" "" , . .

+4
1

, , , , ( bar) patches, lines.

FaceColor , lines.

- , " " , , , colormap.

, legend , , revrsing legend , , colormap ( ).

:

  • sin plot
  • .

, .

, : b.

, :

p_h=get(gca,'children')

10 , b :

  • b (1:10) string
  • b (11: 2: 30) lines
  • b (12: 2: 30) markers

, location: axes, :

    'NorthOutside'       outside plot box near top
    'SouthOutside'       outside bottom
    'EastOutside'        outside right
    'WestOutside'        outside left
    'NorthEastOutside'   outside top right (default for 3-D plots)
    'NorthWestOutside'   outside top left
    'SouthEastOutside'   outside bottom right
    'SouthWestOutside'   outside bottom left

, .

figure
% Initial plot
h_p=plot(0:.1:2*pi,bsxfun(@plus,sin([0:.1:2*pi]),[3:3:30]'),'linewidth',3)
% Initial legend
[h_leg,b]=legend(cellstr(strcat(repmat('sin(x)+',10,1),num2str([3:3:30]'))))
%
% YOUR CODE TO GENERATE NTHE NEW COLORS
%
map = colormap; % current colormap
n = size(b,1);
z = linspace(size(map,1),1,n/3); % there is 1 text and 2 line elements for every data series, so I divide by 3
z = round(z); %otherwise matlab gets angry that indices must be real integers or logicals
MAP = map(z(:),:); % gets elements specified by linspace from colormap
%
% Reverse the legend strings
%
rev_str=flipud(get(b(1:10),'string'))
%
% Get the handles of the lines in the legend
%
b1=b(11:2:30)
%
% Revere the string in the legend
% and update the color of the lne in the plot using the colors defined in
% MAP
%
p_h=get(gca,'children')
for i=1:10
   set(b(i),'string',rev_str{i})
   set(p_h(i),'color',MAP(i,:),'linewidth',3)
end
%
% Reverse the color of the lines in the legend
for i=1:10
   set(b1(i),'color',MAP(i,:),'linewidth',3)
end
%
% Move the legend outside the axes
%
set(h_leg,'location','NorthEastOutside')

enter image description here

enter image description here

, .

+3

Source: https://habr.com/ru/post/1620922/


All Articles