使用linspace

1.linspace颜色展示如下

代码

N = 10;
X = linspace(0,3,1000);
C = linspecer(N) ;
hold off;
for ii=1:N
Y = X+ii*100;
plot(X,Y,'color',C(ii,:),'linewidth',5);
hold on;
end

2.linspace源文件

将下列代码复制保存即可

% 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(0,pi*3,1000);
% Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N);
% C = linspecer(N);
% axes('NextPlot','replacechildren', 'ColorOrder',C);
% plot(X,Y,'linewidth',5)
% ylim([-1.1 1.1]);
%
% SIMPLER LINE COLOR EXAMPLE
% N = 6; X = linspace(0,pi*3,1000);
% C = linspecer(N)
% hold off;
% for ii=1:N
%     Y = sin(X+2*ii*pi/N);
%     plot(X,Y,'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(N,varargin)if nargin==0 % return a colormaplineStyles = linspecer(128);return;
endif ischar(N)lineStyles = linspecer(128,N);return;
endif N<=0 % its empty, nothing else to do herelineStyles=[];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');elseif N>9warning(['Default may be nicer for ' num2str(N) ' for clearer colors use: whitebg(''black''); ']);endendqualFlag = 1;case {'sequential','seq'}lineStyles = colorm(N);return;case {'white','whitefade'}lineStyles = whiteFade(N);return;case 'red'lineStyles = whiteFade(N,'red');return;case 'blue'lineStyles = whiteFade(N,'blue');return;case 'green'lineStyles = whiteFade(N,'green');return;case {'gray','grey'}lineStyles = whiteFade(N,'gray');return;case {'colorblind'}colorblindFlag = 1;otherwisewarning(['parameter ''' varargin{1} ''' not recognized']);end
end
% *.95
% predefine some colormapsset3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}');
set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184]; [ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.85;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}'));
set1 = brighten(colorBrew2mat({[ 55, 126, 184]*.85;[228, 26, 28];[ 77, 175, 74];[ 255, 127, 0];[ 152, 78, 163]}),.8);% colorblindSet = {[215,25,28];[253,174,97];[171,217,233];[44,123,182]};
colorblindSet = {[215,25,28];[253,174,97];[171,217,233]*.8;[44,123,182]*.8};set3 = dim(set3,.93);if colorblindFlagswitch N%     sorry about this line folks. kind of legacy here because I used to%     use individual 1x3 cells instead of nx3 arrayscase 4lineStyles = colorBrew2mat(colorblindSet);otherwisecolorblindFlag = false;warning('sorry unsupported colorblind set for this number, using regular types');end
end
if ~colorblindFlagswitch Ncase 1lineStyles = { [  55, 126, 184]/255};case {2, 3, 4, 5 }lineStyles = set1(1:N);case {6 , 7, 8, 9}lineStyles = set1JL(1:N)';case {10, 11, 12}if qualFlag % force qualitative graphslineStyles = set3(1:N)';else % 10 is a good number to start with the sequential ones.lineStyles = cmap2linspecer(colorm(N));endotherwise % any old case where I need a quick job done.lineStyles = cmap2linspecer(colorm(N));end
end
lineStyles = cell2mat(lineStyles);end% extra functions
function varIn = colorBrew2mat(varIn)
for ii=1:length(varIn) % just divide by 255varIn{ii}=varIn{ii}/255;
end
endfunction varIn = brighten(varIn,varargin) % increase the brightnessif isempty(varargin),frac = .9;
elsefrac = varargin{1};
endfor ii=1:length(varIn)varIn{ii}=varIn{ii}*frac+(1-frac);
end
endfunction varIn = dim(varIn,f)for ii=1:length(varIn)varIn{ii} = f*varIn{ii};end
endfunction vOut = cmap2linspecer(vIn) % changes the format from a double array to a cell array with the right format
vOut = cell(size(vIn,1),1);
for ii=1:size(vIn,1)vOut{ii} = vIn(ii,:);
end
end
%%
% colorm returns a colormap which is really good for creating informative
% heatmap style figures.
% No particular color stands out and it doesn't do too badly for colorblind people either.
% It works by interpolating the data from the
% 'spectral' setting on http://colorbrewer2.org/ set to 11 colors
% It is modified a little to make the brightest yellow a little less bright.
function cmap = colorm(varargin)
n = 100;
if ~isempty(varargin)n = varargin{1};
endif n==1cmap =  [0.2005    0.5593    0.7380];return;
end
if n==2cmap =  [0.2005    0.5593    0.7380;0.9684    0.4799    0.2723];return;
endfrac=.95; % Slight modification from colorbrewer here to make the yellows in the center just a bit darker
cmapp = [158, 1, 66; 213, 62, 79; 244, 109, 67; 253, 174, 97; 254, 224, 139; 255*frac, 255*frac, 191*frac; 230, 245, 152; 171, 221, 164; 102, 194, 165; 50, 136, 189; 94, 79, 162];
x = linspace(1,n,size(cmapp,1));
xi = 1:n;
cmap = zeros(n,3);
for ii=1:3cmap(:,ii) = pchip(x,cmapp(:,ii),xi);
end
cmap = flipud(cmap/255);
endfunction cmap = whiteFade(varargin)
n = 100;
if nargin>0n = varargin{1};
endthisColor = 'blue';if nargin>1thisColor = varargin{2};
end
switch thisColorcase {'gray','grey'}cmapp = [255,255,255;240,240,240;217,217,217;189,189,189;150,150,150;115,115,115;82,82,82;37,37,37;0,0,0];case 'green'cmapp = [247,252,245;229,245,224;199,233,192;161,217,155;116,196,118;65,171,93;35,139,69;0,109,44;0,68,27];case 'blue'cmapp = [247,251,255;222,235,247;198,219,239;158,202,225;107,174,214;66,146,198;33,113,181;8,81,156;8,48,107];case 'red'cmapp = [255,245,240;254,224,210;252,187,161;252,146,114;251,106,74;239,59,44;203,24,29;165,15,21;103,0,13];otherwisewarning(['sorry your color argument ' thisColor ' was not recognized']);
endcmap = interpomap(n,cmapp);
end% Eat a approximate colormap, then interpolate the rest of it up.
function cmap = interpomap(n,cmapp)x = linspace(1,n,size(cmapp,1));xi = 1:n;cmap = zeros(n,3);for ii=1:3cmap(:,ii) = pchip(x,cmapp(:,ii),xi);endcmap = (cmap/255); % flipud??
end

matlab 绘图颜色参考 linspace相关推荐

  1. matlab 绘图颜色—论文配色方案

    (36条消息) 论文配色方案(自用)_minopus的博客-CSDN博客https://blog.csdn.net/sinat_41299610/article/details/106912048?s ...

  2. matlab绘图时将NaN或Inf设为透明色或特定颜色

    matlab绘图时有时会出现数据为nan(not a number)或者inf (无穷大),我们想设置其为透明色或者特定颜色. 以imagesc函数为例. 1. 设置为透明色 h=imagesc(C) ...

  3. Matlab:指定绘图颜色

    Matlab:指定绘图颜色 颜色值的类型 颜色名称或短名称 RGB 三元组 十六进制颜色代码 指定条形图的颜色 指定散点图中的标记颜色 MATLAB® 使用一组默认颜色创建绘图.使用默认颜色创建的不同 ...

  4. Matlab 绘图 曲线颜色自定义

    Matlab 绘图 曲线颜色自定义 同时组合图内间距小 确定绘制曲线的RGB颜色 根据RGB颜色将其除以255归一化到0-1,plot中选择属性'color'为RGB值即可. 示例如下 rn = 2; ...

  5. Matlab绘图高级部分

    转载自:http://www.cnblogs.com/jeromeblog/p/3396494.html 图形是呈现数据的一种直观方式,在用Matlab进行数据处理和计算后,我们一般都会以图形的形式将 ...

  6. 【Matlab 绘图——持续补充中】

    Matlab 绘图--持续补充中 目录 plot() 函数 常用线型.颜色.symbol loglog,semilogx,semilogy,plotyy 图片完善--标题title,坐标轴名称xlab ...

  7. (转载)MatLab绘图

    转载自:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 转载自:http://www.cnblogs.com/jeromebl ...

  8. matlab绘图plot知识汇总

    一.plot() 绘图  1.matlab提供的线条属性: plot(X1,Y1,LineSpec,...)通过参数LineSpec指定曲线的曲线属性,它包括线型.标记符和颜色.plot函数支持同时绘 ...

  9. matlab clabel某些区域不要,Matlab绘图高级部分

    图形是呈现数据的一种直观方式,在用Matlab进行数据处理和计算后,我们一般都会以图形的形式将结果呈现出来.尤其在论文的撰写中,优雅的图形无疑会为文章加分.本篇文章非完全原创,我的工作就是把见到的Ma ...

  10. matlab在绘图区加格栅,实验二(2) MATLAB绘图

    实验二(2)MATLAB绘图 一.实验目的 1.掌握matlab二维图形的绘制方法, 会对所绘图形进行加格栅,图例和标注等一些简单的处理: 2.了解对数坐标图的绘制方法: 3.了解符号函数(显函数.隐 ...

最新文章

  1. 栖息在生态办公室,裸心社与USGBC达成战略合作
  2. CTFshow 反序列化 web268
  3. 对hash签名失败_vue项目中微信jssdk在ios签名失败
  4. python深度神经网络算法_02.深度神经网络算法之Python基础与数据分析
  5. .Net 4.0并行库实用性演练[1]
  6. 产业区块链技术与服务提供商纸贵科技获得B+轮融资
  7. as3程序主类,执行顺序
  8. 终于能理解kmp算法了
  9. Go黑魔法之导出私有函数与私有变量
  10. 一款黑科技神器:uTools
  11. 高等数学张宇18讲 第四讲 一元函数微分学的几何应用
  12. Office 如何双面打印Word文档
  13. python北京房价预测_《安家》热播,我用Python对北京房价进行了分析,结果……...
  14. Given no hashes to check 131 links for project 'pip': discarding no candidates
  15. 剑指 Offer 12. 矩阵中的路径
  16. 【每日早报】2019/08/13
  17. VPB安装过程记录-20200310
  18. 英国金融监管机构加大力度审查违规加密货币公司
  19. 组态王网页服务器,组态王6.55WEB全新发布详细步骤
  20. 项目章程的主要内容#软考高级信息系统项目管理师/高项读书笔记#3

热门文章

  1. 2009最新QQ空间密码QQ相册密码破解
  2. html语言乘法口诀表,0044 使用JavaScript在网页上生成九九乘法口诀表
  3. 001_ucGUI/emWin字体制作(FontCvt.exe)
  4. ToF 3D视觉传感技术详解、应用场景和市场前景
  5. leaflet虚线(leaflet篇.60)
  6. matlab分数阶微分算子,数字图像处理以及数值运算中6种经典的分数阶微分掩模(分数阶微分算子)...
  7. 冥王星P的编曲日志《时光的眼泪》
  8. Origin图选择性粘贴到word出现问题,提示‘word出现问题’解决方法
  9. Day4:《卫报》:我们正面临着第六次大灭绝吗?
  10. 计算机桌面图标右上角出现双箭头符号,电脑桌面图标有箭头怎么办 电脑桌面图片箭头去掉方法【图文】...