Matlab曲线的颜色、线型等参数设置方法
在Matlab绘图时,如果在同一视窗内绘制的曲线特别多的时候,通常需要用不同的颜色和线型将其区分开,否则在黑白色打印输出图像时,用户无法辨别不同属性的曲线。下面是的曲线颜色的配置模板,大家可以直接修改使用,直接引用PlotStyle这个数据结构就可以了。
示例1
1 %% Matlab 线型颜色设置模板 2 clear; 3 close all; 4 %%-----------matlab绘制曲线的颜色,线型,粗细等参数设置方法---------------- 5 PlotStyle={ 6 struct('Color',[1,0,0],'LineStyle','-'),... 7 struct('Color',[0,1,0],'LineStyle','-'),... 8 struct('Color',[0,0,1],'LineStyle','-'),... 9 struct('Color',[0,0,0],'LineStyle','-'),...% 10 struct('Color',[1,1,0],'LineStyle','-'),...%yellow 11 struct('Color',[1,0,1],'LineStyle','-'),...%pink 12 struct('Color',[0,1,1],'LineStyle','-'),... 13 struct('Color',[0.5,0.5,0.5],'LineStyle','-'),...%gray 14 struct('Color',[136,0,21]/255,'LineStyle','-'),...%dark red 15 struct('Color',[255,127,39]/255,'LineStyle','-'),...%orange 16 struct('Color',[0,162,232]/255,'LineStyle','-'),...%Turquoise 17 struct('Color',[163,73,164]/255,'LineStyle','-'),...%purple 18 struct('Color',[1,0,0],'LineStyle','--'),... 19 struct('Color',[0,1,0],'LineStyle','--'),... 20 struct('Color',[0,0,1],'LineStyle','--'),... 21 struct('Color',[0,0,0],'LineStyle','--'),...%
struct('Color',[1,1,0],'LineStyle','--'),...%yellow 22 struct('Color',[1,0,1],'LineStyle','--'),...%pink 23 struct('Color',[0,1,1],'LineStyle','--'),... 24 struct('Color',[0.5,0.5,0.5],'LineStyle','--'),...%gray 25 struct('Color',[136,0,21]/255,'LineStyle','--'),...%dark red 26 struct('Color',[255,127,39]/255,'LineStyle','--'),...%orange 27 struct('Color',[0,162,232]/255,'LineStyle','--'),...%Turquoise 28 struct('Color',[163,73,164]/255,'LineStyle','--'),...%purple 29 struct('Color',[1,0,0],'LineStyle','-.'),... 30 struct('Color',[0,1,0],'LineStyle','-.'),... 31 struct('Color',[0,0,1],'LineStyle','-.'),... 32 struct('Color',[0,0,0],'LineStyle','-.'),...% 33 struct('Color',[1,1,0],'LineStyle',':'),...%yellow 34 struct('Color',[1,0,1],'LineStyle','-.'),...%pink 35 struct('Color',[0,1,1],'LineStyle','-.'),... 36 struct('Color',[0.5,0.5,0.5],'LineStyle','-.'),...%gray 37 struct('Color',[136,0,21]/255,'LineStyle','-.'),...%dark red 38 struct('Color',[255,127,39]/255,'LineStyle','-.'),...%orange 39 struct('Color',[0,162,232]/255,'LineStyle','-.'),...%Turquoise 40 struct('Color',[163,73,164]/255,'LineStyle','-.'),...%purple 41 }; 42 box on; 43 x = 0.1:.1:10; 44 len = length(PlotStyle); 45 for i = 1:len 46 y = x.*sin(x)+i*2;%绘制多条平行的曲线,i*2这一项就是曲线上下的偏移量 47 hold on; 48 plot(x,y,'Color',PlotStyle{1,i}.Color,'LineStyle',PlotStyle{1,i}.LineStyle,'lineWidth', 2);% 这里是调用上述模板结构的方法,注意引用方式,需要做到属性和数值一一对应即可,类似键值对的方式 49 end 50 title('Matlab多种颜色和线型设置范例','FontSize',20,'FontWeight','bold','Color','k'); 51 xlabel('x轴','FontSize',15,'FontWeight','bold','Color','k'); 52 ylabel('y轴','FontSize',15,'FontWeight','bold','Color','k'); 53 54 saveas(gcf, 'result', 'jpg')
Matlab输出结果如下:
参考:https://www.cnblogs.com/cv-pr/p/4670401.html
请发表评论