-
大小: 4KB文件類型: .zip金幣: 2下載: 5 次發(fā)布日期: 2021-05-23
- 語言: Matlab
- 標簽: linspecer.m??Matlab??畫圖顏色??
資源簡介
Matlab畫的線較多時,線的顏色的選取對圖的美觀是有很大的影響的。
Jonathan C. Lansey提供了在不同線上畫不同顏色簡單易用的函數(shù)。

代碼片段和文件信息
%?function?linestyles?=?linspecer(N)
%?This?function?creates?an?Nx3?array?of?N?[R?B?G]?colors
%?These?can?be?used?to?plot?lots?of?lines?with?distinguishable?and?nice
%?looking?colors.
%?
%?linestyles?=?linspecer(N);??makes?N?colors?for?you?to?use:?linestyles(ii:)
%?
%?colormap(linspecer);?set?your?colormap?to?have?easily?distinguishable?
%??????????????????????colors?and?a?pleasing?aesthetic
%?
%?linestyles?=?linspecer(N‘qualitative‘);?forces?the?colors?to?all?be?distinguishable?(up?to?12)
%?linestyles?=?linspecer(N‘sequential‘);?forces?the?colors?to?vary?along?a?spectrum?
%?
%?%?Examples?demonstrating?the?colors.
%?
%?LINE?COLORS
%?N=6;
%?X?=?linspace(0pi*31000);?
%?Y?=?bsxfun(@(xn)sin(x+2*n*pi/N)?X.‘?1:N);?
%?C?=?linspecer(N);
%?axes(‘NextPlot‘‘replacechildren‘?‘ColorOrder‘C);
%?plot(XY‘linewidth‘5)
%?ylim([-1.1?1.1]);
%?
%?SIMPLER?LINE?COLOR?EXAMPLE
%?N?=?6;?X?=?linspace(0pi*31000);
%?C?=?linspecer(N)
%?hold?off;
%?for?ii=1:N
%?????Y?=?sin(X+2*ii*pi/N);
%?????plot(XY‘color‘C(ii:)‘linewidth‘3);
%?????hold?on;
%?end
%?
%?COLORMAP?EXAMPLE
%?A?=?rand(15);
%?figure;?imagesc(A);?%?default?colormap
%?figure;?imagesc(A);?colormap(linspecer);?%?linspecer?colormap
%?
%???See?also?NDHIST?NHIST?PLOT?COLORMAP?43700-cubehelix-colormaps
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?by?Jonathan?Lansey?March?2009-2013??Lansey?at?gmail.com???????????????%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?
%%?credits?and?where?the?function?came?from
%?The?colors?are?largely?taken?from:
%?http://colorbrewer2.org?and?Cynthia?Brewer?Mark?Harrower?and?The?Pennsylvania?State?University
%?
%?
%?She?studied?this?from?a?phsychometric?perspective?and?crafted?the?colors
%?beautifully.
%?
%?I?made?choices?from?the?many?there?to?decide?the?nicest?once?for?plotting
%?lines?in?Matlab.?I?also?made?a?small?change?to?one?of?the?colors?I
%?thought?was?a?bit?too?bright.?In?addition?some?interpolation?is?going?on
%?for?the?sequential?line?styles.
%?
%?
%%
function?linestyles=linspecer(Nvarargin)
if?nargin==0?%?return?a?colormap
????linestyles?=?linspecer(128);
????return;
end
if?ischar(N)
????linestyles?=?linspecer(128N);
????return;
end
if?N<=0?%?its?empty?nothing?else?to?do?here
????linestyles=[];
????return;
end
%?interperet?varagin
qualFlag?=?0;
colorblindFlag?=?0;
if?~isempty(varargin)>0?%?you?set?a?parameter?
????switch?lower(varargin{1})
????????case?{‘qualitative‘‘qua‘}
????????????if?N>12?%?go?home?you?just?can‘t?get?this.
????????????????warning(‘qualitiative?is?not?possible?for?greater?than?12?items?please?reconsider‘);
????????????else
????????????????if?N>9
????????????????????warning([‘Default?may?be?nicer?for?‘?num2str(N)?‘?for?clearer?colors?use:?whitebg(‘‘black‘‘);?‘]);
????????????????end
????????????end
????????????qualFlag?=?1;
????????case?{‘sequential‘‘seq‘}
???????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8449??2015-09-16?11:57??linspecer.m
?????文件????????1318??2015-09-16?11:57??license.txt
評論
共有 條評論