Matlab的plot~各种颜色和线形

Plot是matlab里常用的命令~

可以通过help plot来查询关于plot绘图的相关命令

[c#]  view plain  copy
  1. help plot  

wKiom1ZbCa2SAY0KAABsO3QLY8M595.png

推荐大家自己画画图测试一下~

而且这些命令是可以叠加使用的。即

[c#]  view plain  copy
  1. plot(x,y,'bo');  

可以画出蓝色的圆圈形状图线。


除了matlab自带的这8种颜色,如果需要更丰富的颜色画线,可以使用'color'参数来自定义线条颜色,可以参考这篇博客园的文章。

http://www.cnblogs.com/takeaction/p/3789871.html


那么问题来了,如果采用'color'参数来制定RGB颜色的话只能得到实线,如果我希望用自定义颜色来实现不同线型,即RGB与线型结合的话,该如何实现呢?


一开始我类比之前的办法,在(注意matlab中color的rgb值为0到1,对应于标准的RGB图像值0-255需要在其后除以255)

[c#]  view plain  copy
  1. plot(x,y,'coloro',[0 1 0]);  

或者

[c#]  view plain  copy
  1. plot(x,y,'color',[0 1 0],'o');  

均不能达到目的

后来发现把线型参数放到‘color’之前可以实现我的目的,即

[c#]  view plain  copy
  1. plot(x,y,'o','color',[0 1 0]);  

这样就会发现你的matlab可以实现各种颜色咯!


下面~画一个光盘反面好了。

[c#]  view plain  copy
  1. qpskConstellation = [-1+1i 1+1i; -1-1i 1-1i]/sqrt(2);  
  2. qpsk = reshape(qpskConstellation,1,[]);   
  3. Num  = 40;  
  4. outter = 60;  
  5.  for nn = 1:outter  
  6.   qpsk = qpsk * (outter-1)/outter;  
  7.   c = rand(Num,3);       %随机生成了12种颜色。RGB随机。  
  8.      for idx = 1:Num  
  9.          theta = pi/2/Num*idx;  
  10.          rou = [cos(theta) sin(theta);sin(theta) -cos(theta)];  
  11.      realPart = real(qpsk);  
  12.      imagPart = imag(qpsk);  
  13.      reim = rou * [realPart;imagPart];  
  14.      realPart2 = real(qpsk*0.3);  
  15.      imagPart2 = imag(qpsk*0.3);  
  16.      reim2 = rou * [realPart2;imagPart2];   
  17.      plot(reim(1,:),reim(2,:),'o','color',c(idx,:));  
  18.      hold on;  
  19.      plot(reim2(1,:),reim2(2,:),'.','color',c(idx,:));  
  20.      hold on;  
  21.      pause(0.005);  
  22.      end  
  23.  end  

复制运行一下。嘿嘿~

猜你喜欢

转载自blog.csdn.net/xunan003/article/details/79760603