本周的文件交换选择

我们最好的用户提交

蜘蛛图和更多的论证验证

汪东城本周的选择是spider_plot.经过摩西

有不少“蜘蛛图”在文件交换中,但是这个摩西的这个引起了一些原因。

  • 摩西包括功能内的详细帮助。
帮助spider_plot.
spider_plot创建具有独立轴的爬行器或雷达图。spider_plot(P) spider_plot(___, Name, Value) Input Arguments: (Required) P -用于绘制蜘蛛图的数据点。行是数据组,列是数据点。如果没有指定坐标轴标签和坐标轴限制,将自动生成。[vector | matrix]名称-值对参数(可选)AxesLabels -用于指定每个坐标轴的标签。[auto-generated (default) | cell of strings | 'none'] AxesInterval -用于改变网页之间显示的间隔数量。[3(默认)| integer] AxesPrecision -用于修改轴上显示值的精度级别。输入'none'删除轴文本。[1(默认)| integer | 'none'] AxesLimits -用于手动设置轴的限制。一个2 x大小的矩阵(P, 2)。上面一行是最小轴极限,下面一行是最大轴极限。 [auto-scaled (default) | matrix] FillOption - Used to toggle color fill option. ['off' (default) | 'on'] FillTransparency - Used to set color fill transparency. [0.1 (default) | scalar in range (0, 1)] Color - Used to specify the line color, specified as an RGB triplet. The intensities must be in the range (0, 1). [MATLAB colors (default) | RGB triplet] LineStyle - Used to change the line style of the plots. ['-' (default) | '--' | ':' | '-.' | 'none'] LineWidth - Used to change the line width, where 1 point is 1/72 of an inch. [0.5 (default) | positive value] Marker - Used to change the marker symbol of the plots. ['o' (default) | 'none' | '*' | 's' | 'd' | ...] MarkerSize - Used to change the marker size, where 1 point is 1/72 of an inch. [8 (default) | positive value] FontSize - Used to change the font size of the labels and values displayed on the axes. [10 (default) | scalar value greater than zero] Examples: % Example 1: Minimal number of arguments. All non-specified, optional arguments are set to their default values. Axes labels and limits are automatically generated and set. D1 = [5 3 9 1 2]; % Initialize data points D2 = [5 8 7 2 9]; D3 = [8 2 1 4 6]; P = [D1; D2; D3]; spider_plot(P); legend('D1', 'D2', 'D3', 'Location', 'southoutside'); % Example 2: Manually setting the axes limits. All non-specified, optional arguments are set to their default values. axes_limits = [1, 2, 1, 1, 1; 10, 8, 9, 5, 10]; % Axes limits [min axes limits; max axes limits] spider_plot(P,... 'AxesLimits', axes_limits); % Example 3: Set fill option on. The fill transparency can be adjusted. axes_labels = {'S1', 'S2', 'S3', 'S4', 'S5'}; % Axes properties axes_interval = 2; fill_option = 'on'; fill_transparency = 0.1; spider_plot(P,... 'AxesLabels', axes_labels,... 'AxesInterval', axes_interval,... 'FillOption', fill_option,... 'FillTransparency', fill_transparency); % Example 4: Maximum number of arguments. axes_labels = {'S1', 'S2', 'S3', 'S4', 'S5'}; % Axes properties axes_interval = 4; axes_precision = 'none'; axes_limits = [1, 2, 1, 1, 1; 10, 8, 9, 5, 10]; fill_option = 'on'; fill_transparency = 0.2; colors = [1, 0, 0; 0, 1, 0; 0, 0, 1]; line_style = '--'; line_width = 3; marker_type = 'd'; marker_size = 10; font_size = 12; spider_plot(P,... 'AxesLabels', axes_labels,... 'AxesInterval', axes_interval,... 'AxesPrecision', axes_precision,... 'AxesLimits', axes_limits,... 'FillOption', fill_option,... 'FillTransparency', fill_transparency,... 'Color', colors,... 'LineStyle', line_style,... 'LineWidth', line_width,... 'Marker', marker_type,... 'MarkerSize', marker_size,... 'FontSize', font_size); Author: Moses Yoo, (jyoo at hatci dot com) 2019-10-16: Minor revision to add name-value pairs for customizing color, marker, and line settings. 2019-10-08: Another major revision to convert to name-value pairs and add color fill option. 2019-09-17: Major revision to improve speed, clarity, and functionality Special Thanks: Special thanks to Gabriela Andrade & Andrテゥs Garcia for their feature recommendations and suggested bug fixes.
  • 他包括一个实时脚本示例,展示各种用例

  • 他与他的用户的沟通非常积极评论部分并对更新条目进行了勤奋。

我很高兴看到一块很好的代码,具有强大的错误检查。他大约有100行代码,只需错误检查其功能的输入。他还为可选参数设置默认值。

这是输入代码处理/错误检查代码的原因。

数据属性%%%%点属性[num_data_groups, num_data_points] = size(P);%任选参数的数量numvarargs =长度(变长度输入宗量);%检查偶数的名称 - 值对否则如果Mod (numvarargs, 2) == 1错误('错误:请检查名称值对参数');结尾%创建默认标签Axes_labels = cell(1, num_data_points);%迭代数据点数为了2 = 1: num_data_points%默认轴标签axes_labels {2} = sprintf ('标签%i',ii);结尾%默认参数axes_interval = 3;axes_precision = 1;axes_limits = [];fill_option =“关闭”;fill_transparency = 0.2;颜色= [0,0.4470,0.7410;......0.8500,0.3250,0.0980;......0.9290,0.6940,0.1250;......0.4940、0.1840、0.5560;......0.4660,0.6740,0.1880;......0.3010,0.7450,0.9330;......0.6350, 0.0780, 0.1840);line_style =' - ';line_width = 2;marker_type =“o”;marker_size = 8;font_size = 10;检查是否指定了可选参数如果numvarargs> 1%InitialZE名称值参数name_arguments = varargin(1:2:结束);value_arguments = varargin(2:2:结束);%迭代名称值参数为了II = 1:长度(name_arguments)%根据名称设置值参数转变低(name_arguments {2})情况下'axeslabels'axes_labels = value_arguments {ii};情况下'axesinterval'axes_interval = value_arguments {ii};情况下“axesprecision”axes_precision = value_arguments {II};情况下“axeslimits”axes_limits = value_arguments {ii};情况下'filloption'fill_option = value_arguments {ii};情况下'filltransparency'fill_transparency = value_arguments {2};情况下'颜色'颜色= value_arguments {2};情况下'linestyle'line_style = value_arguments {2};情况下“线宽”line_width = value_arguments {ii};情况下'标记'marker_type = value_arguments {ii};情况下“markersize”marker_size = value_arguments {ii};情况下'字体大小'font_size = value_arguments {II};否则错误('错误:请输入有效的名称值对。);结尾结尾结尾%%%错误检查%%%检查坐标轴标签是否为单元格如果Iscell(Axes_Labels)%检查坐标轴标签是否与点数相同如果长度(axes_labels)〜= num_data_points错误('错误:请确保标签的数量与点数相同。);结尾其他的%检查是否有效字符串条目如果〜Strcmp(axes_labels,'没有任何') 错误('错误:请输入有效的标签或“无”以删除标签。);结尾结尾%检查轴限制是否不为空如果~ isempty (axes_limits)%检查轴是否限制了与点数相同的长度如果尺寸(axes_limits,1)〜= 2 ||size(axes_limits,2)〜= num_data_points错误('错误:请确保最小和最大轴限制匹配数据点数。);结尾结尾%检查轴精度是否为字符串如果〜ISCHAR(AXES_PRECISION)%检查坐标轴属性是否为整数如果地板(axes_interval)〜= axes_interval ||楼层(AXES_PRECISION)〜= AXES_PRECISION错误('错误:请输入轴属性的整数。');结尾检查坐标轴属性是否为正如果Axes_interval < 1 || axes_precision < 1'错误:请输入轴属性的值大于一个。');结尾其他的%检查轴精度是否为有效的字符串条目如果~ strcmp (axes_precision,'没有任何') 错误('错误:无效的轴精度条目。请输入“无”以删除轴文本。);结尾结尾%检查是否没有有效的填充选项争论如果〜ISMember(Fill_Option,{“关闭”'在'}) 错误('错误:请输入“关”或“开”以获取填充选项。);结尾%检查填充透明度是否有效如果Fill_transparency < 0 ||'错误:请在[0,1]之间输入透明度值。');结尾%检查字体大小是否大于零如果font_size <= 0错误('错误:请输入大于零的字体大小。);结尾

这可以转换成参数堵塞。

参数P.(::)翻倍options.axeslabels.{validateaxeslabels(options.axeslabels,p)}= cellstr (“标签 ”+(1:尺寸(p,2)))选项.Xesinterval(1,1)双{mustBeInteger}= 3选项。AxesPrecision{validateaxesprecision(options.axespecision)}= 1选项..Axeslimits.双倍{validateaxeslimits(options.axeslimits,p)}= []选项。填充选项char {mustBeMember (options.FillOption{‘了’,‘’})}=“关闭”选项。FillTransparency(1,1)双{mustBeGreaterThanOrEqual (options.FillTransparency, 0), mustBeLessThanOrEqual (options.FillTransparency, 1)}= 0.1选项.Color.(:,3)双倍{mustbegreatthanorequal(选项.color,0),mustbelessthanorequal(选项.color,1)}=得到(大的,“defaultAxesColorOrder”)选项.LINESTYLE.char {mustbemmber(options.lineStyle,{' - ',' - ',':',' - 。','none'})}=' - '选项。线宽(1,1)双倍{mustbepositive}= 2选项.Marker.char {mustbemmber(options.marker,{'+','o','*','。','x','square','s','diamond','d','v','^','>','<','pentagram','p','hexagram','h','none'})}=“o”选项。市场化(1,1)双倍{mustbepositive}= 8选项。字形大小(1,1)双倍{mustbepositive}= 10结尾

我还为少数参数创建了自定义验证函数。

功能validateAxesPrecision (x)如果isnumeric (x) validateattributes (x) {“双”},{'scalar'“整数”mfilename},'axesprecision'其他的如果~ isequal (x,'没有任何') 错误('axesprecision必须是标量整数或'none''结尾结尾结尾功能validateAxesLimits (axLim P)如果~ isempty (axLim) validateattributes (axLim, {“双”},{'尺寸',[2尺寸(p,2)]},mfilename,'axeslimits'结尾结尾功能validateAxesLabels (axLabels P)如果〜Isequal(Axlabels,'没有任何') validateattributes (axLabels, {“细胞”},{'尺寸',大小(P, 2) [1]}, mfilename,“AxesLabels”结尾结尾

这些变化将代码中的行数减少了500到400.相当整洁!

评论

试一试,让我们知道你的想法在这里或离开A.评论对于摩西。




发布与MATLAB®R2019b

|
  • 打印
  • 发电子邮件

评论

要发表评论,请点击在这里登录您的MathWorks帐户或创建新的。