Matlab 关于plot设置

原文地址:http://blog.csdn.net/xiaojidan2011/article/details/10208137


以前Matlab作图时,要设置好多的变量, 如标题,x轴,y轴间隔, 字体,线条等等特性的设置。这些在写的时候比较麻烦, 今天写了一个集成的函数,直接包含了一个基本的特性,只要用结构体包含进来就可以了。非常的方便。

 例子1

代码

 

[cpp]  view plain copy
  1. % Demo shows how to:  
  2. %    1. use cell arrays when lines have different length  
  3. %    2. use repeating sequence of markers/colors/lineStyles  
  4. %    3. truncate axes to partially-specified limits  
  5.   
  6. clear all  
  7. close all  
  8.   
  9. %% Generate some data  
  10. maxIter = 200;  
  11. optTol = 1e-6;  
  12. err0 = 10000;  
  13. rho = .04;  
  14. rho2 = .04:.005:1;  
  15. for k = 1:maxIter  
  16.     err1(k) = err0/sqrt(k);  
  17.     if err1(k) < optTol  
  18.         break;  
  19.     end  
  20. end  
  21. for k = 1:maxIter  
  22.     err2(k) = err0/k;  
  23.     if err2(k) < optTol  
  24.         break;  
  25.     end  
  26. end  
  27. for k = 1:maxIter  
  28.     err3(k) = err0/k^2;  
  29.     if err3(k) < optTol  
  30.         break;  
  31.     end  
  32. end  
  33. for k = 1:maxIter  
  34.     err4(k) = err0*(1-rho)^k;  
  35.     if err4(k) < optTol  
  36.         break;  
  37.     end  
  38. end  
  39. for k = 1:maxIter  
  40.     err5(k) = err0*(1-sqrt(rho))^k;  
  41.     if err5(k) < optTol  
  42.         break;  
  43.     end  
  44. end  
  45. for k = 1:maxIter  
  46.     err6(k) = err0*prod(1-rho2(1:k));  
  47.     if err6(k) < optTol  
  48.         break;  
  49.     end  
  50. end  
  51.   
  52. % Note: yData does not have same length, and is stored as cell array  
  53. xData = 1:maxIter;  
  54. yData{1} = err1;  
  55. yData{2} = err2;  
  56. yData{3} = err3;  
  57. yData{4} = err4;  
  58. yData{5} = err5;  
  59. yData{6} = err6;  
  60. legendStr = {'Sublinear1','Sublinear2','Sublinear3','Linear1','Linear2','Superlinear'};  
  61.   
  62.   
  63. %% Pretty Plot  
  64.   
  65. figure;  
  66. options.logScale = 2;  
  67.   
  68. % Note: prettyPlot will cycle through the given colors/lineStyles/markers  
  69. options.colors = [1 0 0  
  70.     0 1 0  
  71.     0 0 1];  
  72. options.lineStyles = {':','--','-'};  
  73. options.markers = {'o','s'};  
  74.   
  75.   
  76. % Note: we will truncate the lower y-axis limit but not the upper limit  
  77. options.ylimits = [1e-6 inf];  
  78.   
  79. options.markerSpacing = [25 1  
  80.     25 11  
  81.     25 21  
  82.     25 5  
  83.     25 15  
  84.     25 8];  
  85. options.xlabel = 'Iteration Number';  %% 设置的坐标   
  86. options.ylabel = 'Error';  
  87. options.legend = legendStr;    %%  设置Graph legend  
  88. options.legendLoc = 'SouthWest';   %%  位置     
  89. %%  另外自己也可以写好多的函数。。。。。。很方便。  
  90.   
  91. prettyPlot(xData,yData,options);  
  92. print -dpdf prettyPlot2.pdf  


效果图:

 

 

 

 

关于prettyplot函数:

[cpp]  view plain copy
  1. function [] = prettyPlot(xData,yData,options)  
  2. % prettyPlot(xData,yData,options)  
  3. %  
  4. % available options:  
  5. % legend - cell array containing legend entries (default = [])  
  6. % title - string containing plot title (default = [])  
  7. % xlabel - string containing x-axis label (default = [])  
  8. % ylabel - string containing y-axis label (default = [])  
  9. % lineWidth - width of lines (default = 3)  
  10. % colors - cell array or (n by 3) matrix containing line colors (default = 'b')  
  11. % lineStyles - cell array containing line styles (default = '-')  
  12. % markerSize - size of markers (default = [])  
  13. % markers - cell array containing markers (default = [])  
  14. % markerSpacing - (n by 2) matrix containing spacing between markers and offset for first marker  
  15. % xlimits - 2-vector containing lower and upper limits for x-axis (can be inf to show full range)  
  16. % ylimits - 2-vector containing lower and upper limits for y-axis (can be inf to show full range)  
  17. % logScale - can be 0 (regular scale), 1 (semilogx), or 2 (semilogy)  
  18. % legendLoc - location of legend (default = 'Best')  
  19. % useLines - whether to use lines (default = 1)  
  20. % fillFace - whether to fill markers (default = 1)  
  21. % errors - (n by p by 2) array containing upper and lower error lines  
  22. % errorStyle - line style for error bars  
  23.   
  24. if nargin < 3  
  25.     options = [];  
  26. end  
  27.   
  28. [legendStr,plotTitle,plotXlabel,plotYlabel,lineWidth,colors,lineStyles,...  
  29.     markerSize,markers,markerSpacing,xlimits,ylimits,logScale,legendLoc,...  
  30.     useLines,fillFace,errors,errorStyle,errorColors] = ...  
  31.     myProcessOptions(options,'legend',[],'title',[],'xlabel',[],'ylabel',[],...  
  32.     'lineWidth',3,'colors',[],'lineStyles',[],...  
  33.     'markerSize',12,'markers',[],'markerSpacing',[],...  
  34.     'xlimits',[],'ylimits',[],...  
  35.     'logScale',0,'legendLoc','Best','useLines',1,'fillFace',1,...  
  36.     'errors',[],'errorStyle',{'--'},'errorColors',[]);  
  37.   
  38. if logScale == 1  
  39.     plotFunc = @semilogx;  
  40. elseif logScale == 2  
  41.     plotFunc = @semilogy;  
  42. else  
  43.     plotFunc = @plot;  
  44. end  
  45.   
  46. if useLines == 0  
  47.     defaultStyle = 'b.';  
  48. else  
  49.     defaultStyle = 'b';  
  50. end  
  51.   
  52. if iscell(yData)  
  53.     nLines = length(yData);  
  54. else  
  55.     nLines = size(yData,1);  
  56. end  
  57.   
  58. for i = 1:nLines  
  59.       
  60.     % Get yData for line  
  61.     if iscell(yData)  
  62.         y{i} = yData{i};  
  63.     else  
  64.         y{i} = yData(i,:);  
  65.     end  
  66.       
  67.     % Get xData for line  
  68.     if isempty(xData)  
  69.         x{i} = 1:length(y);  
  70.     elseif iscell(xData)  
  71.         x{i} = xData{i};  
  72.     elseif size(xData,1) == 1  
  73.         x{i} = xData(1:length(y{i}));  
  74.     else  
  75.         x{i} = xData(i,:);  
  76.     end  
  77.       
  78.     % Plot  
  79.     h(i) = plotFunc(x{i},y{i},defaultStyle);  
  80.     hold on;  
  81. end  
  82.   
  83. if isempty(markerSpacing)  
  84.     for i = 1:length(h)  
  85.         h(i) = applyStyle(h(i),i,lineWidth,colors,lineStyles,markers,markerSpacing);  
  86.     end  
  87. else  
  88.     for i = 1:length(h)  
  89.         h(i) = applyStyle(h(i),i,lineWidth,colors,lineStyles,markers,markerSpacing);  
  90.         if ~isempty(markers) && ~isempty(markers{1+mod(i-1,length(markers))})  
  91.             hM = plotFunc(x{i}(markerSpacing(i,2):markerSpacing(i,1):end),y{i}(markerSpacing(i,2):markerSpacing(i,1):end),'b.');  
  92.             applyStyle(hM,i,lineWidth,colors,[],markers,[]);  
  93.             hM = plotFunc(x{i}(markerSpacing(i,2)),y{i}(markerSpacing(i,2)),defaultStyle);  
  94.             h(i) = applyStyle(hM,i,lineWidth,colors,lineStyles,markers,[]);  
  95.         end  
  96.     end  
  97. end  
  98.   
  99. if ~isempty(errors)  
  100.     if isempty(errorColors)  
  101.         errorColors = colors+.75;  
  102.         errorColors(:) = min(errorColors(:),1);  
  103.     end  
  104.     for i = 1:length(h)  
  105.         hL = plotFunc(x{i},errors{i,1},defaultStyle);  
  106.         hU = plotFunc(x{i},errors{i,2},defaultStyle);  
  107.         applyStyle(hL,i,lineWidth,errorColors,errorStyle,[],markerSpacing);  
  108.         applyStyle(hU,i,lineWidth,errorColors,errorStyle,[],markerSpacing);  
  109.     end  
  110. end  
  111.   
  112. set(gca,'FontName','AvantGarde','FontWeight','normal','FontSize',12);  
  113.   
  114. if ~isempty(legendStr)  
  115.     h = legend(h,legendStr);  
  116.     set(h,'FontSize',10,'FontWeight','normal');  
  117.     set(h,'Location','Best');  
  118.     set(h,'Location',legendLoc);  
  119. end  
  120.   
  121. if ~isempty(plotTitle)  
  122.     h = title(plotTitle);  
  123.     set(h,'FontName','AvantGarde','FontSize',12,'FontWeight','bold');  
  124. end  
  125.   
  126. if ~isempty(plotXlabel) || ~isempty(plotYlabel)  
  127.     h1 = xlabel(plotXlabel);  
  128.     h2 = ylabel(plotYlabel);  
  129.     set([h1 h2],'FontName','AvantGarde','FontSize',12,'FontWeight','normal');  
  130. end  
  131.   
  132. set(gca, ...  
  133.     'Box'         , 'on'     , ...  
  134.     'TickDir'     , 'out'     , ...  
  135.     'TickLength'  , [.02 .02] , ...  
  136.     'XMinorTick'  , 'off'      , ...  
  137.     'YMinorTick'  , 'off'      , ...  
  138.     'LineWidth'   , 1         );  
  139.   
  140. if ~isempty(xlimits)  
  141.     xl = xlim;  
  142.     xlimits(xlimits == -inf) = xl(1);  
  143.     xlimits(xlimits == inf) = xl(2);  
  144.     xlim(xlimits);  
  145. end  
  146. if ~isempty(ylimits)  
  147.     yl = ylim;  
  148.     ylimits(ylimits == -inf) = yl(1);  
  149.     ylimits(ylimits == inf) = yl(2);  
  150.     ylim(ylimits);  
  151. end  
  152.   
  153. set(gcf, 'PaperPositionMode''auto');  
  154.   
  155.   
  156.     function [h] = applyStyle(h,i,lineWidth,colors,lineStyles,markers,markerSpacing)  
  157.         hold on;  
  158.         set(h,'LineWidth',lineWidth);  
  159.         if ~isempty(colors)  
  160.             if iscell(colors)  
  161.                 set(h,'Color',colors{1+mod(i-1,length(colors))});  
  162.             else  
  163.                 set(h,'Color',colors(1+mod(i-1,size(colors,1)),:));  
  164.             end  
  165.         end  
  166.         if ~isempty(lineStyles) && useLines  
  167.             if isempty(lineStyles)  
  168.                 set(h,'LineStyle','-');  
  169.             else  
  170.                 if ~isempty(lineStyles{1+mod(i-1,length(lineStyles))})  
  171.                     set(h,'LineStyle',lineStyles{1+mod(i-1,length(lineStyles))});  
  172.                 end  
  173.             end  
  174.         end  
  175.         if ~isempty(markers)  
  176.             if ~isempty(markers{1+mod(i-1,length(markers))})  
  177.                 if isempty(markerSpacing)  
  178.                     set(h,'Marker',markers{1+mod(i-1,length(markers))});  
  179.                     set(h,'MarkerSize',markerSize);  
  180.                     if fillFace  
  181.                         set(h,'MarkerFaceColor',[1 1 .9]);  
  182.                     end  
  183.                 end  
  184.             end  
  185.         end  
  186.     end  
  187. end  

非常的方便啦。。可以直接调用。

例子 2:

[cpp]  view plain copy
  1. clear all; close all;  
  2.   
  3. figure; hold on; set(gca,'FontSize',16); set(gca,'FontName','Times'); set(gcf,'Color',[1,1,1]);  
  4. xlabel('x');ylabel('y');title('a family plot with nice legend');  
  5.   
  6. x       = (1:1000);  
  7. xMid    = (x(1)+2*x(end))/3;  
  8. parVals = [1 1.5 2 3];   
  9.   
  10. num_Markers = 8; %<--------  
  11. LineTypes   = {'-.','-','--'};  
  12. MarkerTypes = {'h','o','s','d','^','v','>','<','p'};  
  13. colors      = {'m','r','b',[1 1 1]*0.5};  
  14. for ip=1:length(parVals)  
  15.     col           =  colors{1+mod(ip,length(colors))};  
  16.     ls            =  LineTypes{1+mod(ip,length(LineTypes))};  
  17.     lm            =  MarkerTypes{1+mod(ip,length(MarkerTypes))};  
  18.     g             =  parVals(ip);  
  19.     y             =  1 + 1/g*abs(1e4./(xMid + (x-xMid/g).^(2-0.2*g)));   % a function that changes with parameter g  
  20.     legCell{ip}   = ['fA, g=',num2str(g)];         %legend text      
  21.     [p1,p2,p3]    = line_fewer_markers(x,y,num_Markers,'color',col,'linestyle',ls, 'linewidth',2, 'marker', lm, 'markerfacecolor',col,'LockOnMax',1,'Spacing','curve','parent',gca);  
  22. end  
  23. lh = legend(legCell,'Location','NorthWest');  


 

效果:

 

[cpp]  view plain copy
  1. clear all; close all;  
  2.   
  3. figure; hold on; set(gca,'FontSize',16); set(gca,'FontName','Times'); set(gcf,'Color',[1,1,1]);  
  4. xlabel('x');ylabel('y');title('a family plot with nice legend');  
  5. t  = 0:0.005:pi;  
  6. line_fewer_markers(t*180/pi,cos(t)         ,9,  '--bs','spacing','curve');  
  7. line_fewer_markers(t*180/pi,sin(t)         ,9,  '-.ro','MFC','g','Mks',6,'linewidth',2);  
  8. grey1 = [1 1 1]*0.5;  
  9. line_fewer_markers(t*180/pi,sin(t).*cos(t) ,15, ':','Mk','p','color',grey1,'MFC',grey1,'linewidth',2,'LockOnMax',1);  
  10. leg = legend('cos','sin','sin*cos','location','best');  


效果:

 

 

[cpp]  view plain copy
  1. clear all; close all;  
  2.   
  3. figure; hold on; set(gca,'FontSize',16); set(gca,'FontName','Times'); set(gcf,'Color',[1,1,1]);  
  4. xlabel('x');ylabel('y');title('a family plot with nice legend');  
  5. t  = 0:0.005:pi;  
  6. grey1 = [1 1 1]*0.5;  
  7. % line_fewer_markers(t*180/pi,cos(t)         ,9,  '--bs','spacing','curve');  
  8. % line_fewer_markers(t*180/pi,sin(t)         ,9,  '-.ro','MFC','g','Mks',6,'linewidth',2);  
  9. % line_fewer_markers(t*180/pi,sin(t).*cos(t) ,15, ':','Mk','p','color',grey1,'MFC',grey1,'linewidth',2,'LockOnMax',1);  
  10.   
  11. line_fewer_markers(t*180/pi,cos(t)         ,9,  '--bs','spacing','curve','LegendLine','off');  
  12. line_fewer_markers(t*180/pi,sin(t)         ,9,  '-.ro','MFC','g','Mks',6,'linewidth',2,'LegendLine','off');  
  13. line_fewer_markers(t*180/pi,sin(t).*cos(t) ,15, ':','Mk','p','color',grey1,'MFC',grey1,'linewidth',2,'LockOnMax',1,'LegendLine','off');  
  14.   
  15.   
  16. leg = legend('cos','sin','sin*cos','location','best');  


效果:

 

% line_fewer_markers  函数:

[cpp]  view plain copy
  1. % line_fewer_markers - line with controlled amount of markers and correct legend behaviour  
  2. %   
  3. %   LINE_FEWER_MARKERS(X,Y,NUM_MARKERS) adds the line in vectors X and Y to the current axes  
  4. %   with exactly NUM_MARKERS markers drawn.  
  5. %   
  6. %   LINE_FEWER_MARKERS(X,Y,NUM_MARKERS,'PropertyName',PropertyValue,...) plots the data  
  7. %   stored in the vectors X and Y.  
  8. %  
  9. %   LINE_FEWER_MARKERS returns handles to LINE/MARKER objects.  
  10. %   
  11. %   [H1,H2,H3] = LINE_FEWER_MARKERS(X,Y,NUM_MARKERS,'PropertyName',PropertyValue,...)   
  12. %   performs the actions as above and returns the handles of all the plotted lines/markers.  
  13. %   H1    = handle to the main marker(1 point); it may be put in array and used with legend  
  14. %   H2    = handle to the continuous line (as in H2=plot())  
  15. %   H3    = handle to all other markers  
  16. %  
  17. %   Property/Value pairs and descriptions:  
  18. %         
  19. %       Spacing    - 'x'      : ordinary uniform along x  
  20. %                  - 'curve'  : equal lengths along curve y(x)  
  21. %   
  22. %       LockOnMax  - 0        : first marker on 1st data point  
  23. %                  - 1        : offset all markers such that one marker on first max of y(x)  
  24. %   
  25. %       LegendLine - 'on'     : default, reproduce linestyle also in legend  
  26. %                  - 'off'    : shows only marker in legend  
  27. %   
  28. %       LineSpec: same as for LINE: LineStyle,LineWidth,Marker,MarkerSize,MarkerFaceColor...  
  29. %  
  30. %  
  31. %   Example: plot 3 curves with 9,9, and 15 markers each, using different input styles  
  32. %   
  33. %      figure; hold on;  
  34. %      t  = 0:0.005:pi;  
  35. %      line_fewer_markers(t*180/pi,cos(t) ,9,  '--bs','spacing','curve');  
  36. %      line_fewer_markers(t*180/pi,sin(t) ,9,  '-.ro','MarkerFaceColor','g', ...  
  37. %                                                     'markersize',6,'linewidth',2);  
  38. %      grey1 = [1 1 1]*0.5;  
  39. %      line_fewer_markers(t*180/pi,sin(t).*cos(t) ,15, ':','marker','h','color',grey1, ...  
  40. %                                    'markerfacecolor',grey1,'linewidth',2,'LockOnMax',1);  
  41. %      leg = legend('cos','sin','sin*cos','location','best');  
  42. %  
  43. % Inspired by Ioannis Filippidis's answer:   
  44. % http://www.mathworks.com/matlabcentral/answers/2165-too-many-markers  
  45. %   
  46. % rev.3, Massimo Ciacci, August 19, 2013  
  47. %   
  48. function [H1,H2,H3] = line_fewer_markers(x,y,num_Markers, varargin)  
  49.   
  50.   
  51. %% find marker spec in varargin and remove it; extract special params: LockOnMax,Spacing  
  52. if mod(length(varargin),2)  
  53.     if ischar(varargin{1})  
  54.       linspec   = varargin{1};  
  55.       extraArgs = varargin(2:end);  
  56.       [varargInNoMk,varargInNoMkNoLn,lm,ms,mfc,LockOnMax,Spacing,LegendLine] = parseargsLineSpec(linspec,extraArgs);  
  57.     else  
  58.       error('odd sized [param | val] list, missing one param ?');  
  59.     end  
  60. else  
  61.       [varargInNoMk,varargInNoMkNoLn,lm,ms,mfc,LockOnMax,Spacing,LegendLine] = parseargs(varargin{:});    
  62. end  
  63.   
  64. %% input size check  
  65. if  isvector(x) &&  isvector(y)  
  66.     % make x,y row vectors  
  67.     if iscolumn(x), x = x.'; end  
  68.     if iscolumn(y), y = y.'; end  
  69. else  
  70.     error('line_fewer_markers: input arguments must be 1D vectors');  
  71. end  
  72.   
  73. % How the method works: plots 3 times:   
  74. % a) once only the line with all points with the style                                                'r--' and invisible handle,   
  75. % b) last time the markers, using fewer points with style                                             'ro' and again invisible handle.  
  76. % c) once with a visible handle, only the first point, using the complete style you specified         (e.g. 'r--o')  
  77.   
  78. %% a) once only the line with all points with the style                                                                  
  79. H2 = line(x   ,y   ,varargInNoMk{:});                               %no markers here  
  80. hasbehavior(H2,'legend',0);                                         %prevent to appear in legends!  
  81.   
  82. %% b) last time the markers, using fewer points with style                                                               
  83. if     (strcmp(Spacing,'x') || strcmp(Spacing,'X'))  
  84.     ti = round(linspace(1,length(x),num_Markers));  
  85. elseif (strcmp(Spacing,'curve') || strcmp(Spacing,'Curve'))  
  86.     scaleY     = 3/4; % 1/1 figure aspect ratio  
  87.     yNrm       = (y-min(y))./(max(y)-min(y))*scaleY;                %NORMALIZE y scale in [0 1], height of display is prop to max(abs(y))          
  88.     xNrm       = (x-min(x))./(max(x)-min(x));                       %NORMALIZE x scale in [0 1]     
  89.       
  90.     if (sum(isinf(yNrm))>0) || sum(isinf(x))>0                      %spacing along curve not possible with infinites  
  91.         ti = round(linspace(1,length(x),num_Markers));   
  92.     else  
  93.         t        = 1:length(x);                                  
  94.         s        = [0 cumsum(sqrt(diff(xNrm).^2+diff(yNrm).^2))];   %measures length along the curve  
  95.         si       = (0:num_Markers-1)*s(end)/(num_Markers-1);        %equally spaced lengths along the curve  
  96.         si(end)  = s(end);                                          %fix last point to be within the curve                      
  97.         ti       = round(interp1(s,t,si));                          %find x index of markers  
  98.     end  
  99. else  
  100.     error('invalid spacing parameter');  
  101. end  
  102. if LockOnMax  
  103.     %set one ti on max if found  
  104.     [Mv,idx]   = max(y); idx=idx(1);  
  105.     [mv,idxti] = min(abs(idx-ti));  
  106.     deltati    = ti(idxti)-idx;  
  107.     ti         = max(1,min(ti-deltati,length(y)));  
  108. end      
  109. xi = x(ti);  
  110. yi = y(ti);             
  111. H3 = line(xi,yi,varargInNoMkNoLn{:},'Marker',lm,'MarkerSize',ms,'MarkerFaceColor',mfc,'LineStyle','none');  %plot markers only  
  112. hasbehavior(H3,'legend',0); %prevent to appear in legends!  
  113.   
  114. %% c) once with a visible handle, only the first point, using the complete style you specified                           
  115. if strcmp(LegendLine,'on')  
  116.     H1 = line(xi(1),yi(1),varargInNoMk{:},'Marker',lm,'MarkerSize',ms,'MarkerFaceColor',mfc);  
  117. else  
  118.     H1 = line(xi(1),yi(1),varargInNoMk{:},'linestyle','none','Marker',lm,'MarkerSize',ms,'MarkerFaceColor',mfc);  
  119. end  
  120.   
  121.   
  122. %-------------------------------------------------------------  
  123. % PARSE FUNCTIONS  
  124. %-------------------------------------------------------------  
  125. % varargInNoMk = list of property pairs, marker specs removed   
  126. % varargInNoMkNoLn = list of property pairs, marker specs and line specs removed   
  127. function [varargInNoMk,varargInNoMkNoLn,lm,ms,mfc,LockOnMax,Spacing,LegendLine] = parseargs(varargin)  
  128. lm =[]; ms =[]; mfc=[]; LockOnMax=[]; Spacing=[]; LegendLine=[];  
  129. varargInNoMk = {};  
  130. varargInNoMkNoLn = {};  
  131. arg_index = 1;  
  132. while arg_index <= length(varargin)  
  133.     arg = varargin{arg_index};  
  134.     % extract special params and marker specs from arg list  
  135.     if strcmp(arg,'marker') || strcmp(arg,'Marker') || strcmp(arg,'Mk')  || strcmp(arg,'mk')  
  136.         lm              = varargin{arg_index+1};  
  137.     elseif strcmp(arg,'MarkerSize') || strcmp(arg,'markersize') || strcmp(arg,'Mks')  || strcmp(arg,'mks')  
  138.         ms              = varargin{arg_index+1};          
  139.     elseif strcmp(arg,'MarkerFaceColor') || strcmp(arg,'markerfacecolor')||strcmp(arg,'MFC')||strcmp(arg,'mfc')  
  140.         mfc             = varargin{arg_index+1};  
  141.     elseif strcmp(arg,'LockOnMax') || strcmp(arg,'lockonmax')  
  142.         LockOnMax       = varargin{arg_index+1};  
  143.     elseif strcmp(arg,'Spacing')   || strcmp(arg,'spacing')   
  144.         Spacing         = varargin{arg_index+1};  
  145.     elseif strcmp(arg,'LegendLine')   || strcmp(arg,'legendline')   
  146.         LegendLine      = varargin{arg_index+1};  
  147.     else  
  148.         % keep other params in arg list for line command  
  149.         varargInNoMk    = {varargInNoMk{:},  varargin{arg_index},  varargin{arg_index+1}};  
  150.         if ~strcmp(arg,'LineStyle') && ~strcmp(arg,'linestyle')   
  151.            % exclude line params for marker only plot  
  152.            varargInNoMkNoLn = {varargInNoMkNoLn{:},  varargin{arg_index},  varargin{arg_index+1}};  
  153.         end  
  154.     end  
  155.     arg_index = arg_index + 2;    
  156. end  
  157. %EXTRA DEFAULTS ARE SET HERE  
  158. if isempty(lm),         lm          = 'o'   ; end  
  159. if isempty(ms),         ms          = 10    ; end  
  160. if isempty(mfc),        mfc         = 'none'; end  
  161. if isempty(LockOnMax),  LockOnMax   = 1     ; end  
  162. if isempty(Spacing),    Spacing     = 'x'   ; end %%'x' -> marker delta-x constant; 'curve' : spacing constant along the curve length  
  163. if isempty(LegendLine), LegendLine  = 'on'  ; end   
  164.   
  165. %-------------------------------------------------------------  
  166. % Parse LineSpec string and other arguments  
  167. % varargInNoMk     = list of property pairs, marker specs removed   
  168. % varargInNoMkNoLn = list of property pairs, marker specs and line specs removed   
  169. function [varargInNoMk,varargInNoMkNoLn,lm,ms,mfc,LockOnMax,Spacing,LegendLine] = parseargsLineSpec(linspec, extraArgs)  
  170. %          b     blue          .     point              -     solid  
  171. %          g     green         o     circle             :     dotted  
  172. %          r     red           x     x-mark             -.    dashdot   
  173. %          c     cyan          +     plus               --    dashed     
  174. %          m     magenta       *     star             (none)  no line  
  175. %          y     yellow        s     square  
  176. %          k     black         d     diamond  
  177. %          w     white         v     triangle (down)  
  178. %                              ^     triangle (up)  
  179. %                              <     triangle (left)  
  180. %                              >     triangle (right)  
  181. %                              p     pentagram  
  182. %                              h     hexagram  
  183. varargInNoMk     = {};  
  184. varargInNoMkNoLn = {};  
  185.   
  186. foundLine           = false;  
  187. stringSearch        = {'-.','--','-',':'};  
  188. for ii=1:4  
  189.     if strfind(linspec, stringSearch{ii})  
  190.         foundLine   = true;  
  191.         ls          = stringSearch{ii};  
  192.         linspec     = setdiff(linspec,ls);  
  193.         break  
  194.     end  
  195. end  
  196. if foundLine  
  197.     varargInNoMk    = {varargInNoMk{:},'lineStyle',ls};  
  198. else  
  199.     varargInNoMk    = {varargInNoMk{:},'lineStyle','-'};      
  200. end  
  201.   
  202. if ~isempty(linspec)  
  203.     foundCol            = false;  
  204.     stringSearch        = {'b','g','r','c','m','y','k','w'};  
  205.     for ii=1:8  
  206.         if strfind(linspec, stringSearch{ii})  
  207.             foundCol    = true;  
  208.             colspec     = stringSearch{ii};  
  209.             linspec     = setdiff(linspec,colspec);  
  210.             break  
  211.         end  
  212.     end  
  213.     if foundCol  
  214.         varargInNoMk    = {varargInNoMk{:},'color',colspec};  
  215.         varargInNoMkNoLn    = {varargInNoMkNoLn{:},'color',colspec};  
  216.     end      
  217. end  
  218.   
  219. if ~isempty(linspec)  
  220.     foundMk             = false;  
  221.     stringSearch        = {'.','o','x','+','*','s','d','v','^','<','>','p','h'};  
  222.     for ii=1:13  
  223.         if strfind(linspec, stringSearch{ii})  
  224.             foundMk     = true;  
  225.             mkspec      = stringSearch{ii};  
  226.             break  
  227.         end  
  228.     end  
  229.     if foundMk, lm = mkspec; else lm = 'none'; end  
  230. else  
  231.     lm = 'none';  
  232. end  
  233.   
  234.   
  235. [extraArgs1,unused,lm2,ms,mfc,LockOnMax,Spacing,LegendLine] = parseargs(extraArgs{:});  
  236. if strcmp(lm,'none') && ~strcmp(lm2,'none') %if other marker specified in Property Pairs take that one  
  237.     lm = lm2;  
  238. end  
  239. varargInNoMk       = {varargInNoMk{:},extraArgs1{:}};  
  240. varargInNoMkNoLn   = {varargInNoMkNoLn{:},extraArgs1{:}};  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值