user2223044
user2223044

Reputation: 1

MATLAB plot loses colors after setting legend

I'm new to MATLAB/programming in general, so forgive my noobness. Anyways, I'm trying to create a 3 colored plot of the global distribution of some data. I ultimately want this graph to be the top portion of a figure that will contain 2 different types of plots. My issue is, that after I set the location of the legend, the colors on the spatial plot and in the legend default to black. I assume the problem lies in the coding for the legend, because when I remove that, the plots turn out fine.

Anyway, here's the code:

tm = zeros(3,group(1).ny);
hl = zeros(3,1); 

proxycolor = zeros(3,3);

icon{1,1}= [1 0 0];   icon{1,2}= '^'; icon{1,3} = 'Raw Data';
icon{2,1}= [1 1 0];   icon{2,2}= 'v'; icon{2,3} = 'Quality Controlled Data';
icon{3,1}= [0 1 0];   icon{3,2}= '*'; icon{3,3} = 'Screened Data';


fig('Data Availability'),clf
subplot(3,1,1:2)
m_proj('Robinson','clong',180);
m_grid('xtick',[0:60:360],'tickdir','out','ytick',[-90:30:90], 'color',dkgr, 'fontsize',8,'fontname','Times New Roman');

m_coast('color','k');


for j = 1:3
    group(j).lon(group(j).lon<0) = group(j).lon(group(j).lon<0) + 360;
    tm(j,:) = group(1).tm;
end

for j = 1:3
    proxycolor(j,:) = icon{j,1};
    hl(j)=m_line(group(j).lon,group(j).lat,'color',icon{j,1},'marker',icon{j,2},'MarkerFaceColor',icon{j,1},'MarkerSize',7,'LineStyle','none');
end


%The problem lies below here somewhere
[LEGH,OBJH,OUTH,OUTM]=legend(hl(:),icon{:,3});pause; 
set(LEGH,'FontName','Times','FontSize',10);
set(OUTH,'Color','k','MarkerFaceColor','k','Markersize',8);
legend boxoff

Upvotes: 0

Views: 288

Answers (1)

erikced
erikced

Reputation: 732

According to the documentation to legend OUTH, whose color you are setting to black, contains handles to the lines and patches in the plot, i.e.

set(OUTH,'Color','k','MarkerFaceColor','k','Markersize',8);

is causing your problem and should probably be removed or altered.

Upvotes: 0

Related Questions