forked from NewGuy012/spider_plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spider_plot.m
1226 lines (1108 loc) · 44.2 KB
/
spider_plot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function spider_plot(P, varargin)
%spider_plot Create a spider or radar plot with individual axes.
%
% Syntax:
% spider_plot(P)
% spider_plot(P, Name, Value, ...)
%
% Input Arguments:
% (Required)
% P - The data points used to plot the spider chart. The
% rows are the groups of data and the columns are the
% data points. The axes labels and axes limits are
% automatically generated if not specified.
% [vector | matrix]
%
% Name-Value Pair Arguments:
% (Optional)
% AxesLabels - Used to specify the label each of the axes.
% [auto-generated (default) | cell array of character vectors | 'none']
%
% AxesInterval - Used to change the number of intervals displayed
% between the webs.
% [3 (default) | integer]
%
% AxesPrecision - Used to change the precision level on the value
% displayed on the axes.
% [1 (default) | integer | vector]
%
% AxesDisplay - Used to change the number of axes in which the
% axes text are displayed. 'None' or 'one' can be used
% to simplify the plot appearance for normalized data.
% ['all' (default) | 'none' | 'one' | 'data']
%
% AxesLimits - Used to manually set the axes limits. A matrix of
% 2 x size(P, 2). The top row is the minimum axes
% limits and the bottow row is the maximum axes limits.
% [auto-scaled (default) | matrix]
%
% FillOption - Used to toggle fill color option.
% ['off' (default) | 'on' | cell array of character vectors]
%
% FillTransparency - Used to set fill color transparency.
% [0.1 (default) | scalar in range (0, 1) | vector]
%
% 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' | cell array of character vectors]
%
% LineWidth - Used to change the line width, where 1 point is
% 1/72 of an inch.
% [0.5 (default) | positive value | vector]
%
% LineTransparency - Used to set the line color transparency.
% [1 (default) | scalar in range (0, 1) | vector]
%
% Marker - Used to change the marker symbol of the plots.
% ['o' (default) | 'none' | '*' | 's' | 'd' | ... | cell array of character vectors]
%
% MarkerSize - Used to change the marker size, where 1 point is
% 1/72 of an inch.
% [36 (default) | positive value | vector | vector]
%
% MarkerTransparency-Used to set the marker color transparency.
% [1 (default) | scalar in range (0, 1)]
%
% AxesFont - Used to change the font type of the values
% displayed on the axes.
% [Helvetica (default) | supported font name]
%
% LabelFont - Used to change the font type of the labels.
% [Helvetica (default) | supported font name]
%
% AxesFontSize - Used to change the font size of the values
% displayed on the axes.
% [10 (default) | scalar value greater than zero]
%
% AxesFontColor - Used to change the font color of the values
% displayed on the axes.
% [black (default) | RGB triplet]
%
% LabelFontSize - Used to change the font size of the labels.
% [10 (default) | scalar value greater than zero]
%
% Direction - Used to change the direction of rotation of the
% plotted data and axis labels.
% ['clockwise' (default) | 'counterclockwise']
%
% AxesDirection - Used to change the direction of axes.
% ['normal' (default) | 'reverse' | cell array of character vectors]
%
% AxesLabelsOffset - Used to adjust the position offset of the axes
% labels.
% [0.2 (default) | positive value]
%
% AxesDataOffset - Used to adjust the position offset of the data labels
% when AxesDisplay is set to 'data'.
% [0.1 (default) | positive value]
%
% AxesScaling - Used to change the scaling of the axes.
% ['linear' (default) | 'log' | cell array of character vectors]
%
% AxesColor - Used to change the color of the spider axes.
% [grey (default) | RGB triplet | hexadecimal color code]
%
% AxesLabelsEdge - Used to change the edge color of the axes labels.
% [black (default) | RGB triplet | hexadecimal color code | 'none']
%
% AxesOffset - Used to change to axes offset from the origin.
% [1 (default) | any integer less than the axes interval]
%
% AxesZoom - Used to change zoom of axes.
% [0.7 (default) | scalar in range (0, 1)]
%
% AxesHorzAlign - Used to change the horizontal alignment of axes tick labels.
% ['center' (default) | 'left' | 'right' | 'quadrant']
%
% AxesVertAlign - Used to change the vertical aligment of axes tick labels.
% ['middle' (default) | 'top' | 'cap' | 'bottom' | 'baseline' | 'quadrant']
%
% PlotVisible - Used to change the visibility of the plotted lines and markers.
% ['on' (default) | 'off']
%
% AxesTickLabels - Used to change the axes tick labels.
% ['data' (default) | cell array of character vectors]
%
% AxesInterpreter - Used to change the text interpreter of axes labels and axes tick labels.
% ['tex' (default) | 'latex' | 'none' | cell array of character vectors]
%
% 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];
% 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 and axes precision.
% All non-specified, optional arguments are set to their
% default values.
%
% D1 = [5 3 9 1 2];
% D2 = [5 8 7 2 9];
% D3 = [8 2 1 4 6];
% P = [D1; D2; D3];
% spider_plot(P,...
% 'AxesLimits', [1, 2, 1, 1, 1; 10, 8, 9, 5, 10],... % [min axes limits; max axes limits]
% 'AxesPrecision', [0, 1, 1, 1, 1]);
%
% % Example 3: Set fill option on. The fill transparency can be adjusted.
%
% D1 = [5 3 9 1 2];
% D2 = [5 8 7 2 9];
% D3 = [8 2 1 4 6];
% P = [D1; D2; D3];
% spider_plot(P,...
% 'AxesLabels', {'S1', 'S2', 'S3', 'S4', 'S5'},...
% 'AxesInterval', 2,...
% 'FillOption', {'on', 'on', 'off'},...
% 'FillTransparency', [0.2, 0.1, 0.1]);
%
% % Example 4: Maximum number of arguments.
%
% D1 = [5 3 9 1 2];
% D2 = [5 8 7 2 9];
% D3 = [8 2 1 4 6];
% P = [D1; D2; D3];
% spider_plot(P,...
% 'AxesLabels', {'S1', 'S2', 'S3', 'S4', 'S5'},...
% 'AxesInterval', 4,...
% 'AxesPrecision', 0,...
% 'AxesDisplay', 'one',...
% 'AxesLimits', [1, 2, 1, 1, 1; 10, 8, 9, 5, 10],...
% 'FillOption', 'on',...
% 'FillTransparency', 0.2,...
% 'Color', [1, 0, 0; 0, 1, 0; 0, 0, 1],...
% 'LineStyle', {'--', '-', '--'},...
% 'LineWidth', [1, 2, 3],...
% 'LineTransparency', 1,...
% 'Marker', {'o', 'd', 's'},...
% 'MarkerSize', [8, 10, 12],...
% 'MarkerTransparency', 1,...
% 'AxesFont', 'Times New Roman',...
% 'LabelFont', 'Times New Roman',...
% 'AxesFontColor', 'k',...
% 'AxesFontSize', 12,...
% 'LabelFontSize', 10,...
% 'Direction', 'clockwise',...
% 'AxesDirection', {'reverse', 'normal', 'normal', 'normal', 'normal'},...
% 'AxesLabelsOffset', 0.2,...
% 'AxesDataOffset', 0.1,...
% 'AxesScaling', 'linear',...
% 'AxesColor', [0.6, 0.6, 0.6],...
% 'AxesLabelsEdge', 'none',...
% 'AxesOffset', 1,...
% 'AxesZoom', 1,...
% 'AxesHorzAlign', 'quadrant',...
% 'AxesVertAlign', 'quadrant',...
% 'PlotVisible', 'on',...
% 'AxesTickLabels', 'data',...
% 'AxesInterpreter', 'tex');
%
% % Example 5: Excel-like radar charts.
%
% D1 = [5 0 3 4 4];
% D2 = [2 1 5 5 4];
% P = [D1; D2];
% spider_plot(P,...
% 'AxesInterval', 5,...
% 'AxesPrecision', 0,...
% 'AxesDisplay', 'one',...
% 'AxesLimits', [0, 0, 0, 0, 0; 5, 5, 5, 5, 5],...
% 'FillOption', 'on',...
% 'FillTransparency', 0.1,...
% 'Color', [139, 0, 0; 240, 128, 128]/255,...
% 'LineWidth', 4,...
% 'Marker', 'none',...
% 'AxesFontSize', 14,...
% 'LabelFontSize', 10,...
% 'AxesColor', [0.8, 0.8, 0.8],...
% 'AxesLabelsEdge', 'none');
% title('Excel-like Radar Chart',...
% 'FontSize', 14);
% legend_str = {'D1', 'D2'};
% legend(legend_str, 'Location', 'southoutside');
%
% % Example 6: Logarithimic scale on specified axes. Axes limits and axes
% intervals can be individually set as well.
%
% D1 = [5 3 9 1 1];
% D2 = [5 8 7 2 10];
% D3 = [8 2 1 4 100];
% P = [D1; D2; D3];
% spider_plot(P,...
% 'AxesInterval', 2,...
% 'AxesPrecision', 0,...
% 'AxesFontSize', 10,...
% 'AxesLabels', {'Linear Scale', 'Linear Scale', 'Linear Scale', 'Linear Scale', 'Logarithimic Scale'},...
% 'AxesScaling', {'linear', 'linear', 'linear', 'linear', 'log'},...
% 'AxesLimits', [1, 1, 1, 1, 1; 10, 10, 10, 10, 100]);
% legend('D1', 'D2', 'D3', 'Location', 'northeast');
%
% % Example 7: Spider plot with subplot feature.
%
% D1 = [5 3 9 1 2];
% D2 = [5 8 7 2 9];
% D3 = [8 2 1 4 6];
% P = [D1; D2; D3];
% subplot(1, 2, 1)
% spider_plot(P,...
% 'AxesInterval', 1,...
% 'AxesPrecision', 0);
% subplot(1, 2, 2)
% spider_plot(P,...
% 'AxesInterval', 1,...
% 'AxesPrecision', 0);
%
% % Example 8: Spider plot with values only on data points.
%
% D1 = [1 3 4 1 2];
% D2 = [5 8 7 5 9];
% P = [D1; D2];
% spider_plot(P,...
% 'AxesLimits', [1, 1, 1, 1, 1; 10, 10, 10, 10, 10],...
% 'AxesDisplay', 'data',...
% 'AxesLabelsOffset', 0.2,...
% 'AxesDataOffset', 0.1,...
% 'AxesFontColor', [0, 0, 1; 1, 0, 0]);
% legend('D1', 'D2', 'Location', 'southoutside');
%
% Author:
% Moses Yoo, (juyoung.m.yoo at gmail dot com)
% 2022-01-03: Fix legend to include line and marker attributes.
% 2021-11-24: Fix axes labels misalignment. Add option to set offset for
% data display values.
% 2021-11-09: Add option to change the text interpreter of axes labels
% and axes tick labels.
% 2021-11-01: -Allow for plot lines and markers to be hidden.
% -Allow for custom text of axes tick labels.
% 2021-04-17: Fix data display values when log scale is set.
% 2021-04-13: Add option to adjust line and marker transparency.
% 2021-04-08: -Add option for data values to be displayed on axes.
% -Add support to adjust axes font colors.
% 2021-03-19: -Allow axes values to be shifted.
% -Allow axes zoom level to be adjusted.
% 2020-12-09: Allow fill option and fill transparency for each data group.
% 2020-12-01: Added support for adjust the axes offset from origin.
% 2020-11-30: Allow for one data group without specified axes limits.
% 2020-11-30: Added support for changing axes and label font type.
% 2020-11-06: Fix bug in reverse axes direction feature.
% 2020-10-08: Adjust axes precision to be set to one or more axis.
% 2020-09-30: Updated examples and added ability to reverse axes direction.
% 2020-07-05: Added feature to change spider axes and axes labels edge color.
% 2020-06-17: Allow logarithmic scale to be set to one or more axis.
% 2020-03-26: Added feature to allow different line styles, line width,
% marker type, and marker sizes for the data groups.
% 2020-02-12: Fixed condition and added error checking for when only one
% data group is plotted.
% 2020-01-27: Corrected bug where only 7 entries were allowed in legend.
% 2020-01-06: Added support for subplot feature.
% 2019-11-27: Add option to change axes to logarithmic scale.
% 2019-11-15: Add feature to customize the plot rotational direction and
% the offset position of the axis labels.
% 2019-10-23: Minor revision to set starting axes as the vertical line.
% Add customization option for font sizes and axes display.
% 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, Alex Grenyer,
% Tobias Kern, Zafar Ali, Christophe Hurlin, Roman, Mariusz Sepczuk,
% Mohamed Abubakr, Nicolai, Jingwei Too, Cedric Jamet, Richard Ruff,
% Marie-Kristin Schreiber, Juan Carlos Vargas Rubio, Anthony Wang,
% Pauline Oeuvray, Oliver Nicholls, Yu-Chi Chen & Fabrizio De Caro for
% their feature recommendations and bug finds.
%%% Data Properties %%%
% Point properties
[num_data_groups, num_data_points] = size(P);
% Number of optional arguments
numvarargs = length(varargin);
% Check for even number of name-value pair argments
if mod(numvarargs, 2) == 1
error('Error: Please check name-value pair arguments');
end
% Create default labels
axes_labels = cell(1, num_data_points);
% Iterate through number of data points
for ii = 1:num_data_points
% Default axes labels
axes_labels{ii} = sprintf('Label %i', ii);
end
% Default arguments
axes_interval = 3;
axes_precision = 1;
axes_display = 'all';
axes_limits = [];
fill_option = 'off';
fill_transparency = 0.2;
colors = lines(num_data_groups);
line_style = '-';
line_width = 2;
line_transparency = 1;
marker_type = 'o';
marker_size = 36;
marker_transparency = 1;
axes_font = 'Helvetica';
label_font = 'Helvetica';
axes_font_size = 10;
axes_font_color = [0, 0, 0];
label_font_size = 10;
direction = 'clockwise';
axes_direction = 'normal';
axes_labels_offset = 0.2;
axes_data_offset = 0.1;
axes_scaling = 'linear';
axes_color = [0.6, 0.6, 0.6];
axes_labels_edge = 'k';
axes_offset = 1;
axes_zoom = 0.7;
axes_horz_align = 'center';
axes_vert_align = 'middle';
plot_visible = 'on';
axes_tick_labels = 'data';
axes_interpreter = 'tex';
% Check if optional arguments were specified
if numvarargs > 1
% Initialze name-value arguments
name_arguments = varargin(1:2:end);
value_arguments = varargin(2:2:end);
% Iterate through name-value arguments
for ii = 1:length(name_arguments)
% Set value arguments depending on name
switch lower(name_arguments{ii})
case 'axeslabels'
axes_labels = value_arguments{ii};
case 'axesinterval'
axes_interval = value_arguments{ii};
case 'axesprecision'
axes_precision = value_arguments{ii};
case 'axesdisplay'
axes_display = value_arguments{ii};
case 'axeslimits'
axes_limits = value_arguments{ii};
case 'filloption'
fill_option = value_arguments{ii};
case 'filltransparency'
fill_transparency = value_arguments{ii};
case 'color'
colors = value_arguments{ii};
case 'linestyle'
line_style = value_arguments{ii};
case 'linewidth'
line_width = value_arguments{ii};
case 'linetransparency'
line_transparency = value_arguments{ii};
case 'marker'
marker_type = value_arguments{ii};
case 'markersize'
marker_size = value_arguments{ii};
case 'markertransparency'
marker_transparency = value_arguments{ii};
case 'axesfont'
axes_font = value_arguments{ii};
case 'labelfont'
label_font = value_arguments{ii};
case 'axesfontsize'
axes_font_size = value_arguments{ii};
case 'axesfontcolor'
axes_font_color = value_arguments{ii};
case 'labelfontsize'
label_font_size = value_arguments{ii};
case 'direction'
direction = value_arguments{ii};
case 'axesdirection'
axes_direction = value_arguments{ii};
case 'axeslabelsoffset'
axes_labels_offset = value_arguments{ii};
case 'axesdataoffset'
axes_data_offset = value_arguments{ii};
case 'axesscaling'
axes_scaling = value_arguments{ii};
case 'axescolor'
axes_color = value_arguments{ii};
case 'axeslabelsedge'
axes_labels_edge = value_arguments{ii};
case 'axesoffset'
axes_offset = value_arguments{ii};
case 'axeszoom'
axes_zoom = value_arguments{ii};
case 'axeshorzalign'
axes_horz_align = value_arguments{ii};
case 'axesvertalign'
axes_vert_align = value_arguments{ii};
case 'plotvisible'
plot_visible = value_arguments{ii};
case 'axesticklabels'
axes_tick_labels = value_arguments{ii};
case 'axesinterpreter'
axes_interpreter = value_arguments{ii};
otherwise
error('Error: Please enter in a valid name-value pair.');
end
end
end
%%% Error Check %%%
% Check if axes labels is a cell
if iscell(axes_labels)
% Check if the axes labels are the same number as the number of points
if length(axes_labels) ~= num_data_points
error('Error: Please make sure the number of labels is the same as the number of points.');
end
else
% Check if valid char entry
if ~contains(axes_labels, 'none')
error('Error: Please enter in valid labels or "none" to remove labels.');
end
end
% Check if axes limits is not empty
if ~isempty(axes_limits)
% Check if the axes limits same length as the number of points
if size(axes_limits, 1) ~= 2 || size(axes_limits, 2) ~= num_data_points
error('Error: Please make sure the min and max axes limits match the number of data points.');
end
% Lower and upper limits
lower_limits = axes_limits(1, :);
upper_limits = axes_limits(2, :);
% Difference in upper and lower limits
diff_limits = upper_limits - lower_limits;
% Check to make sure upper limit is greater than lower limit
if any(diff_limits < 0)
error('Error: Please make sure max axes limits are greater than the min axes limits.');
end
% Check the range of axes limits
if any(diff_limits == 0)
error('Error: Please make sure the min and max axes limits are different.');
end
end
% Check if axes precision is numeric
if isnumeric(axes_precision)
% Check is length is one
if length(axes_precision) == 1
% Repeat array to number of data points
axes_precision = repmat(axes_precision, num_data_points, 1);
elseif length(axes_precision) ~= num_data_points
error('Error: Please specify the same number of axes precision as number of data points.');
end
else
error('Error: Please make sure the axes precision is a numeric value.');
end
% Check if axes properties are an integer
if floor(axes_interval) ~= axes_interval || any(floor(axes_precision) ~= axes_precision)
error('Error: Please enter in an integer for the axes properties.');
end
% Check if axes properties are positive
if axes_interval < 1 || any(axes_precision < 0)
error('Error: Please enter a positive value for the axes properties.');
end
% Check if axes display is valid char entry
if ~ismember(axes_display, {'all', 'none', 'one', 'data'})
error('Error: Invalid axes display entry. Please enter in "all", "none", or "one" to set axes text.');
end
% Check if fill option is valid
if any(~ismember(fill_option, {'off', 'on'}))
error('Error: Please enter either "off" or "on" for fill option.');
end
% Check if fill transparency is valid
if any(fill_transparency < 0) || any(fill_transparency > 1)
error('Error: Please enter a transparency value between [0, 1].');
end
% Check if line transparency is valid
if any(line_transparency < 0) || any(line_transparency > 1)
error('Error: Please enter a transparency value between [0, 1].');
end
% Check if marker transparency is valid
if any(marker_transparency < 0) || any(marker_transparency > 1)
error('Error: Please enter a transparency value between [0, 1].');
end
% Check if font size is greater than zero
if axes_font_size <= 0 || label_font_size <= 0
error('Error: Please enter a font size greater than zero.');
end
% Check if direction is valid char entry
if ~ismember(direction, {'counterclockwise', 'clockwise'})
error('Error: Invalid direction entry. Please enter in "counterclockwise" or "clockwise" to set direction of rotation.');
end
% Check if axes direction is valid char entry
if ~ismember(axes_direction, {'normal', 'reverse'})
error('Error: Invalid axes direction entry. Please enter in "normal" or "reverse" to set axes direction.');
end
% Check if axes labels offset is positive
if axes_labels_offset < 0
error('Error: Please enter a positive for the axes labels offset.');
end
% Check if axes data offset is positive
if axes_data_offset < 0
error('Error: Please enter a positive for the axes data offset.');
end
% Check if axes scaling is valid
if any(~ismember(axes_scaling, {'linear', 'log'}))
error('Error: Invalid axes scaling entry. Please enter in "linear" or "log" to set axes scaling.');
end
% Check if axes offset is valid
if floor(axes_offset)~=axes_offset || axes_offset < 0 || axes_offset > axes_interval
error('Error: Invalid axes offset entry. Please enter in an integer value that is between [0, axes_interval].');
end
% Check if axes zoom value is valid
if ~isnumeric(axes_zoom) || length(axes_zoom) ~= 1 || axes_zoom < 0 || axes_zoom > 1
error('Error: Please enter an axes zoom value between [0, 1].');
end
% Check if axes horizontal alignment is valid
if any(~ismember(axes_horz_align, {'center', 'left', 'right', 'quadrant'}))
error('Error: Invalid axes horizontal alignment entry.');
end
% Check if axes vertical alignment is valid
if any(~ismember(axes_vert_align, {'middle', 'top', 'cap', 'bottom', 'baseline', 'quadrant'}))
error('Error: Invalid axes vertical alignment entry.');
end
% Check if plot visible is valid
if ~ismember(plot_visible, {'on', 'off'})
error('Error: Invalid plot visible entry. Please enter in "on" or "off" to set plot visiblity.');
end
% Check if axes interpreter is valid
if any(~ismember(axes_interpreter, {'tex', 'latex', 'none'}))
error('Error: Please enter either "tex", "latex", or "none" for axes interpreter option.');
end
% Check if axes interpreter is a char
if ischar(axes_interpreter)
% Convert to cell array of char
axes_interpreter = cellstr(axes_interpreter);
% Repeat cell to number of data groups
axes_interpreter = repmat(axes_interpreter, length(axes_labels), 1);
elseif iscellstr(axes_interpreter)
% Check is length is one
if length(axes_interpreter) == 1
% Repeat cell to number of data groups
axes_interpreter = repmat(axes_interpreter, length(axes_labels), 1);
elseif length(axes_interpreter) ~= length(axes_labels)
error('Error: Please specify the same number of axes interpreters as axes labels.');
end
else
error('Error: Please make sure the axes interpreter is a char or a cell array of char.');
end
% Check if axes tick labels is valid
if iscell(axes_tick_labels)
if length(axes_tick_labels) ~= axes_interval+1
error('Error: Invalid axes tick labels entry. Please enter in a cell array with the same length of axes interval + 1.');
end
else
if ~strcmp(axes_tick_labels, 'data')
error('Error: Invalid axes tick labels entry. Please enter in "data" or a cell array of desired tick labels.');
end
end
% Check if axes scaling is a cell
if iscell(axes_scaling)
% Check is length is one
if length(axes_scaling) == 1
% Repeat array to number of data groups
axes_scaling = repmat(axes_scaling, num_data_points, 1);
elseif length(axes_scaling) ~= num_data_points
error('Error: Please specify the same number of axes scaling as number of data points.');
end
else
% Repeat array to number of data groups
axes_scaling = repmat({axes_scaling}, num_data_points, 1);
end
% Check if line style is a char
if ischar(line_style)
% Convert to cell array of char
line_style = cellstr(line_style);
% Repeat cell to number of data groups
line_style = repmat(line_style, num_data_groups, 1);
elseif iscellstr(line_style)
% Check is length is one
if length(line_style) == 1
% Repeat cell to number of data groups
line_style = repmat(line_style, num_data_groups, 1);
elseif length(line_style) ~= num_data_groups
error('Error: Please specify the same number of line styles as number of data groups.');
end
else
error('Error: Please make sure the line style is a char or a cell array of char.');
end
% Check if line width is numeric
if isnumeric(line_width)
% Check is length is one
if length(line_width) == 1
% Repeat array to number of data groups
line_width = repmat(line_width, num_data_groups, 1);
elseif length(line_width) ~= num_data_groups
error('Error: Please specify the same number of line width as number of data groups.');
end
else
error('Error: Please make sure the line width is a numeric value.');
end
% Check if marker type is a char
if ischar(marker_type)
% Convert to cell array of char
marker_type = cellstr(marker_type);
% Repeat cell to number of data groups
marker_type = repmat(marker_type, num_data_groups, 1);
elseif iscellstr(marker_type)
% Check is length is one
if length(marker_type) == 1
% Repeat cell to number of data groups
marker_type = repmat(marker_type, num_data_groups, 1);
elseif length(marker_type) ~= num_data_groups
error('Error: Please specify the same number of line styles as number of data groups.');
end
else
error('Error: Please make sure the line style is a char or a cell array of char.');
end
% Check if line width is numeric
if isnumeric(marker_size)
if length(marker_size) == 1
% Repeat array to number of data groups
marker_size = repmat(marker_size, num_data_groups, 1);
elseif length(marker_size) ~= num_data_groups
error('Error: Please specify the same number of line width as number of data groups.');
end
else
error('Error: Please make sure the line width is numeric.');
end
% Check if axes direction is a cell
if iscell(axes_direction)
% Check is length is one
if length(axes_direction) == 1
% Repeat array to number of data points
axes_direction = repmat(axes_direction, num_data_points, 1);
elseif length(axes_direction) ~= num_data_points
error('Error: Please specify the same number of axes direction as number of data points.');
end
else
% Repeat array to number of data points
axes_direction = repmat({axes_direction}, num_data_points, 1);
end
% Check if fill option is a cell
if iscell(fill_option)
% Check is length is one
if length(fill_option) == 1
% Repeat array to number of data groups
fill_option = repmat(fill_option, num_data_groups, 1);
elseif length(fill_option) ~= num_data_groups
error('Error: Please specify the same number of fill option as number of data groups.');
end
else
% Repeat array to number of data groups
fill_option = repmat({fill_option}, num_data_groups, 1);
end
% Check if fill transparency is numeric
if isnumeric(fill_transparency)
% Check is length is one
if length(fill_transparency) == 1
% Repeat array to number of data groups
fill_transparency = repmat(fill_transparency, num_data_groups, 1);
elseif length(fill_transparency) ~= num_data_groups
error('Error: Please specify the same number of fill transparency as number of data groups.');
end
else
error('Error: Please make sure the transparency is a numeric value.');
end
% Check if line transparency is numeric
if isnumeric(line_transparency)
% Check is length is one
if length(line_transparency) == 1
% Repeat array to number of data groups
line_transparency = repmat(line_transparency, num_data_groups, 1);
elseif length(line_transparency) ~= num_data_groups
error('Error: Please specify the same number of line transparency as number of data groups.');
end
else
error('Error: Please make sure the transparency is a numeric value.');
end
% Check if marker transparency is numeric
if isnumeric(marker_transparency)
% Check is length is one
if length(marker_transparency) == 1
% Repeat array to number of data groups
marker_transparency = repmat(marker_transparency, num_data_groups, 1);
elseif length(marker_transparency) ~= num_data_groups
error('Error: Please specify the same number of marker transparency as number of data groups.');
end
else
error('Error: Please make sure the transparency is a numeric value.');
end
% Check if axes display is data
if strcmp(axes_display, 'data')
if size(axes_font_color, 1) ~= num_data_groups
% Check axes font color dimensions
if size(axes_font_color, 1) == 1 && size(axes_font_color, 2) == 3
axes_font_color = repmat(axes_font_color, num_data_groups, 1);
else
error('Error: Please specify axes font color as a RGB triplet normalized to 1.');
end
end
end
%%% Axes Scaling Properties %%%
% Selected data
P_selected = P;
% Check axes scaling option
log_index = strcmp(axes_scaling, 'log');
% If any log scaling is specified
if any(log_index)
% Initialize copy
P_log = P_selected(:, log_index);
% Logarithm of base 10, account for numbers less than 1
P_log = sign(P_log) .* log10(abs(P_log));
% Minimum and maximun log limits
min_limit = min(min(fix(P_log)));
max_limit = max(max(ceil(P_log)));
recommended_axes_interval = max_limit - min_limit;
% Warning message
warning('For the log scale values, recommended axes limit is [%i, %i] with an axes interval of %i.',...
10^min_limit, 10^max_limit, recommended_axes_interval);
% Replace original
P_selected(:, log_index) = P_log;
end
%%% Figure Properties %%%
% Grab current figure
fig = gcf;
% Set figure background
fig.Color = 'white';
% Reset axes
cla reset;
% Current axes handle
ax = gca;
% Axis limits
hold on;
axis square;
scaling_factor = 1 + (1 - axes_zoom);
axis([-1, 1, -1, 1] * scaling_factor);
% Axis properties
ax.XTickLabel = [];
ax.YTickLabel = [];
ax.XColor = 'none';
ax.YColor = 'none';
% Polar increments
theta_increment = 2*pi/num_data_points;
full_interval = axes_interval + 1;
rho_offset = axes_offset/full_interval;
%%% Scale Data %%%
% Pre-allocation
P_scaled = zeros(size(P_selected));
axes_range = zeros(3, num_data_points);
% Check axes scaling option
axes_direction_index = strcmp(axes_direction, 'reverse');
% Iterate through number of data points
for ii = 1:num_data_points
% Check for one data group and no axes limits
if num_data_groups == 1 && isempty(axes_limits)
% Group of points
group_points = P_selected(:, :);
else
% Group of points
group_points = P_selected(:, ii);
end
% Check for log axes scaling option
if log_index(ii)
% Minimum and maximun log limits
min_value = min(fix(group_points));
max_value = max(ceil(group_points));
else
% Automatically the range of each group
min_value = min(group_points);
max_value = max(group_points);
end
% Range of min and max values
range = max_value - min_value;
% Check if axes_limits is not empty
if ~isempty(axes_limits)
% Check for log axes scaling option
if log_index(ii)
% Logarithm of base 10, account for numbers less than 1
axes_limits(:, ii) = sign(axes_limits(:, ii)) .* log10(abs(axes_limits(:, ii))); %#ok<AGROW>
end
% Manually set the range of each group
min_value = axes_limits(1, ii);
max_value = axes_limits(2, ii);
range = max_value - min_value;
% Check if the axes limits are within range of points
if min_value > min(group_points) || max_value < max(group_points)
error('Error: Please make the manually specified axes limits are within range of the data points.');
end
end
% Check if range is valid
if range == 0
error('Error: Range of data values is not valid. Please specify the axes limits.');
end
% Scale points to range from [0, 1]
P_scaled(:, ii) = ((P_selected(:, ii) - min_value) / range);
% If reverse axes direction is specified
if axes_direction_index(ii)
% Store to array
axes_range(:, ii) = [max_value; min_value; range];
P_scaled(:, ii) = -(P_scaled(:, ii) - 1);
else
% Store to array
axes_range(:, ii) = [min_value; max_value; range];
end
% Add offset of [rho_offset] and scaling factor of [1 - rho_offset]
P_scaled(:, ii) = P_scaled(:, ii) * (1 - rho_offset) + rho_offset;
end
%%% Polar Axes %%%
% Polar coordinates
rho_increment = 1/full_interval;
rho = 0:rho_increment:1;
% Check rotational direction
switch direction
case 'counterclockwise'
% Shift by pi/2 to set starting axis the vertical line
theta = (0:theta_increment:2*pi) + (pi/2);
case 'clockwise'
% Shift by pi/2 to set starting axis the vertical line
theta = (0:-theta_increment:-2*pi) + (pi/2);
end
% Remainder after using a modulus of 2*pi
theta = mod(theta, 2*pi);
% Iterate through each theta
for ii = 1:length(theta)-1
% Convert polar to cartesian coordinates
[x_axes, y_axes] = pol2cart(theta(ii), rho);
% Plot webs
h = plot(x_axes, y_axes,...
'LineWidth', 1.5,...
'Color', axes_color);
% Turn off legend annotation
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
end
% Iterate through each rho
for ii = 2:length(rho)
% Convert polar to cartesian coordinates
[x_axes, y_axes] = pol2cart(theta, rho(ii));
% Plot axes
h = plot(x_axes, y_axes,...
'Color', axes_color);
% Turn off legend annotation
h.Annotation.LegendInformation.IconDisplayStyle = 'off';
end
% Set end index depending on axes display argument
switch axes_display
case 'all'
theta_end_index = length(theta)-1;
case 'one'
theta_end_index = 1;
case 'none'
theta_end_index = 0;
case 'data'
theta_end_index = 0;
end
% Rho start index and offset interval
rho_start_index = axes_offset+1;
offset_interval = full_interval - axes_offset;
% Alignment for axes labels
horz_align = axes_horz_align;
vert_align = axes_vert_align;
% Iterate through each theta
for ii = 1:theta_end_index
% Convert polar to cartesian coordinates
[x_axes, y_axes] = pol2cart(theta(ii), rho);
% Check if horizontal alignment is quadrant based