Mercurial > octave
comparison scripts/plot/appearance/xticklabels.m @ 31871:9546e993e9ee
[xyz]ticklabels.m: Allow empty char array input for Matlab compatibility (bug #63859).
* xticklabels.m, yticklabels.m, zticklabels.m: Detect empty input ({}, [], or
'') and map to empty cell array {}. Use 'lower' rather than 'tolower' and
don't transform input argument so that any error messages will report exactly
what was typed.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 01 Mar 2023 22:16:34 -0800 |
parents | 597f3ee61a48 |
children | 2e484f9f1f18 |
comparison
equal
deleted
inserted
replaced
31870:6a2638cbea96 | 31871:9546e993e9ee |
---|---|
86 | 86 |
87 if (isempty (hax)) | 87 if (isempty (hax)) |
88 hax = gca (); | 88 hax = gca (); |
89 endif | 89 endif |
90 | 90 |
91 if (! (iscell (arg) || isnumeric (arg) || ischar (arg))) | |
92 print_usage (); | |
93 endif | |
94 | |
95 if (isempty (arg)) | |
96 arg = {}; # Either '' or [] are converted empty cell array | |
97 endif | |
98 | |
91 if (iscell (arg) || isnumeric (arg)) | 99 if (iscell (arg) || isnumeric (arg)) |
92 if (nargout > 0) | 100 if (nargout > 0) |
93 error ("xticklabels: too many output arguments requested"); | 101 error ("xticklabels: too many output arguments requested"); |
94 endif | 102 endif |
95 | 103 |
97 ## NOTE: Matlab accepts a cell array, but a non-vector numeric array will | 105 ## NOTE: Matlab accepts a cell array, but a non-vector numeric array will |
98 ## simply produce a black set of labels without error or warning. | 106 ## simply produce a black set of labels without error or warning. |
99 ## This implementation allows for a numeric array, which is handled in | 107 ## This implementation allows for a numeric array, which is handled in |
100 ## the same order as Matlab handles a cell array | 108 ## the same order as Matlab handles a cell array |
101 arg = num2cell (arg(:)); | 109 arg = num2cell (arg(:)); |
102 | |
103 endif | 110 endif |
104 | 111 |
105 ## Convert any numeric elements to characters, make it a 1-D cell array. | 112 ## Convert any numeric elements to characters, make it a 1-D cell array. |
106 arg = cellfun (@num2str, arg, "UniformOutput", false)(:); | 113 arg = cellfun (@num2str, arg, "UniformOutput", false)(:); |
107 | 114 |
112 set (hax, "xticklabel", arg, | 119 set (hax, "xticklabel", arg, |
113 "xticklabelmode", "manual", | 120 "xticklabelmode", "manual", |
114 "xtickmode", "manual"); | 121 "xtickmode", "manual"); |
115 | 122 |
116 elseif (ischar (arg)) | 123 elseif (ischar (arg)) |
117 arg = tolower (arg); | 124 switch (lower (arg)) |
118 switch (arg) | |
119 case "mode" | 125 case "mode" |
120 labels = get (hax, "xticklabelmode"); | 126 labels = get (hax, "xticklabelmode"); |
121 | 127 |
122 case {"auto", "manual"} | 128 case {"auto", "manual"} |
123 if (nargout > 0) | 129 if (nargout > 0) |
129 otherwise | 135 otherwise |
130 error ("xticklabels: invalid option: %s", arg); | 136 error ("xticklabels: invalid option: %s", arg); |
131 | 137 |
132 endswitch | 138 endswitch |
133 | 139 |
134 else | |
135 print_usage (); | |
136 endif | 140 endif |
137 | 141 |
138 endfunction | 142 endfunction |
139 | 143 |
140 | 144 |