Showing posts with label plot colour. Show all posts
Showing posts with label plot colour. Show all posts

Tuesday, 11 March 2014

How to put legends only to some of the lines in a Matlab Plot?

1. Use the 'plot' handles.

x1 = 1:10;
y1blue = 2 .* x1;


y2green = 2 .* y1;

y3red = y2 + 5;

h1 = plot(x1,y1blue ,'b');
hold on;

h2 = plot(y2green,'g');
h3 = plot(y3red,'r');

%Legend all the line plots
legend('Y1blue','Y2green', 'Y3red');


%Legend only Y1 and Y2
legend([h1 h2],{'Y1','Y2'});

2. Another method to control the 'legend content' is given HERE


3. How to use numbers in the legend?

legend({['PRN' num2str(1)],['PRN' num2str(2)]});

Sunday, 10 November 2013

How to save Matlab graphs/plots with high resolution/quality (suitable for publications)?

Use the export-figure file from:

http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig

Examples can be found at:

https://sites.google.com/site/oliverwoodford/software/export_fig


Other settings:

% Colour adjustmentsset(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot

% Set figure format - Size
% set(gcf,'Position',[xpos ypos scale*width scale*height])
set(gcf, 'Position', [100 100 150 150])
%or,
scrsz = get(0,'ScreenSize'); %returns the screen size
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);

% Saving figure using export_fig
figName = [fName(1:end-4) '.png'];

saveas(gcf, figName);
export_fig(figName);

% Example:

function [] = SaveAndExportFigure(figName)
set(gcf, 'Color', 'w'); %background outside the plot
set(gca, 'Color', 'w'); %background of the plot
scrsz = get(0,'ScreenSize');
set(gcf, 'Position', [0 0 0.85*scrsz(3) 1*scrsz(4)]);
saveas(gcf, figName);
export_fig(figName);