|
| 1 | +classdef Test_plotlyfig < matlab.unittest.TestCase |
| 2 | + methods (Test) |
| 3 | + function testLinePlotData(tc) |
| 4 | + fig = figure("Visible","off"); |
| 5 | + y = [0.0301 0.4411 0.7007 0.7030 0.5102 0.6122 0.7464 0.8014 0.3367 0.5641]; |
| 6 | + x = 1:10; |
| 7 | + plot(x,y); |
| 8 | + |
| 9 | + p = plotlyfig(fig,"visible","off"); |
| 10 | + |
| 11 | + tc.verifyNumElements(p.data, 1); |
| 12 | + tc.verifyEqual(p.data{1}, struct( ... |
| 13 | + "type", 'scatter', ... |
| 14 | + "xaxis", 'x1', ... |
| 15 | + "yaxis", 'y1', ... |
| 16 | + "visible", true, ... |
| 17 | + "name", '', ... |
| 18 | + "mode", 'lines', ... |
| 19 | + "x", x, ... |
| 20 | + "y", y, ... |
| 21 | + "line", struct( ... |
| 22 | + "color", "rgb(0,114,189)", ... |
| 23 | + "width", 0.5, ... |
| 24 | + "dash", 'solid' ... |
| 25 | + ), ... |
| 26 | + "marker", struct( ... |
| 27 | + "size", 3.6, ... |
| 28 | + "line", struct( ... |
| 29 | + "width", 0.5 ... |
| 30 | + ), ... |
| 31 | + "color", "rgb(0,114,189)" ... |
| 32 | + ), ... |
| 33 | + "showlegend", false ... |
| 34 | + ), AbsTol=1e-6); |
| 35 | + end |
| 36 | + |
| 37 | + function testAreaPlotData(tc) |
| 38 | + fig = figure("Visible","off"); |
| 39 | + y = [0.6297 0.9559 0.7551 0.5261 0.8501 0.8160 0.1321 0.7607 0.6172 0.3976]; |
| 40 | + x = 1:10; |
| 41 | + area(x,y); |
| 42 | + |
| 43 | + p = plotlyfig(fig,"visible","off"); |
| 44 | + |
| 45 | + tc.verifyNumElements(p.data, 1); |
| 46 | + tc.verifyEqual(p.data{1}, struct( ... |
| 47 | + "xaxis", "x1", ... |
| 48 | + "yaxis", "y1", ... |
| 49 | + "type", "scatter", ... |
| 50 | + "x", x, ... |
| 51 | + "y", y, ... |
| 52 | + "name", '', ... |
| 53 | + "visible", true, ... |
| 54 | + "fill", "tozeroy", ... |
| 55 | + "mode", "lines", ... |
| 56 | + "line", struct( ... |
| 57 | + "color", "rgba(0,0,0,1.000000)", ... |
| 58 | + "width", 0.5, ... |
| 59 | + "dash", "solid" ... |
| 60 | + ), ... |
| 61 | + "fillcolor", "rgba(0,114,189,1.000000)", ... |
| 62 | + "showlegend", true ... |
| 63 | + )); |
| 64 | + end |
| 65 | + |
| 66 | + function testScatterPlotData(tc) |
| 67 | + fig = figure("Visible","off"); |
| 68 | + x = linspace(0,3*pi,200); |
| 69 | + y = cos(x) + rand(1,200); |
| 70 | + scatter(x,y); |
| 71 | + |
| 72 | + p = plotlyfig(fig,"visible","off"); |
| 73 | + |
| 74 | + tc.verifyNumElements(p.data, 1); |
| 75 | + tc.verifyEqual(p.data{1}, struct( ... |
| 76 | + "type", "scatter", ... |
| 77 | + "xaxis", "x1", ... |
| 78 | + "yaxis", "y1", ... |
| 79 | + "mode", "markers", ... |
| 80 | + "visible", true, ... |
| 81 | + "name", '', ... |
| 82 | + "x", x, ... |
| 83 | + "y", y, ... |
| 84 | + "marker", struct( ... |
| 85 | + "sizeref", 1, ... |
| 86 | + "sizemode", 'area', ... |
| 87 | + "size", 36 * ones(size(x)), ... |
| 88 | + "line", struct( ... |
| 89 | + "width", 0.7500, ... |
| 90 | + "color", 'rgb(0.000000,113.985000,188.955000)' ... |
| 91 | + ), ... |
| 92 | + "symbol", 'circle', ... |
| 93 | + "color", "rgba(0,0,0,0)", ... |
| 94 | + "opacity", 1 ... |
| 95 | + ), ... |
| 96 | + "showlegend", false ... |
| 97 | + )); |
| 98 | + end |
| 99 | + |
| 100 | + function testHistogramPlotData(tc) |
| 101 | + fig = figure("Visible","off"); |
| 102 | + values = [0.6297 0.9559 0.7551 0.5261 0.8501 0.8160 0.1321 0.7607 0.6172 0.3976]; |
| 103 | + histogram(values); |
| 104 | + |
| 105 | + p = plotlyfig(fig,"visible","off"); |
| 106 | + |
| 107 | + tc.verifyNumElements(p.data, 1); |
| 108 | + tc.verifyEqual(p.data{1}, struct( ... |
| 109 | + "xaxis", "x1", ... |
| 110 | + "yaxis", "y1", ... |
| 111 | + "type", "bar", ... |
| 112 | + "x", [0.15 0.45 0.75 1.05], ... |
| 113 | + "width", [0.3 0.3 0.3 0.3], ... |
| 114 | + "y", [1 2 6 1], ... |
| 115 | + "name", 'values', ... |
| 116 | + "marker", struct( ... |
| 117 | + "line", struct( ... |
| 118 | + "width", 0.5, ... |
| 119 | + "color", "rgba(0,0,0,1.000000)" ... |
| 120 | + ), ... |
| 121 | + "color", "rgba(0,114,189,0.600000)" ... |
| 122 | + ), ... |
| 123 | + "opacity", 0.75, ... |
| 124 | + "visible", true, ... |
| 125 | + "showlegend", true ... |
| 126 | + ), AbsTol=1e-6); |
| 127 | + end |
| 128 | + |
| 129 | + function testVerticalBarPlotData(tc) |
| 130 | + fig = figure("Visible","off"); |
| 131 | + x = 1:12; |
| 132 | + y = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]; |
| 133 | + bar(x,y); |
| 134 | + |
| 135 | + p = plotlyfig(fig,"visible","off"); |
| 136 | + |
| 137 | + tc.verifyNumElements(p.data, 1); |
| 138 | + tc.verifyEqual(p.data{1}, struct( ... |
| 139 | + "xaxis", "x1", ... |
| 140 | + "yaxis", "y1", ... |
| 141 | + "type", "bar", ... |
| 142 | + "name", '', ... |
| 143 | + "visible", true, ... |
| 144 | + "orientation", "v", ... |
| 145 | + "x", x, ... |
| 146 | + "y", y, ... |
| 147 | + "marker", struct( ... |
| 148 | + "line", struct( ... |
| 149 | + "color", "rgba(0,0,0,1.000000)", ... |
| 150 | + "width", 0.5, ... |
| 151 | + "dash", "solid" ... |
| 152 | + ), ... |
| 153 | + "color", "rgba(0,114,189,1.000000)" ... |
| 154 | + ), ... |
| 155 | + "showlegend", true ... |
| 156 | + )); |
| 157 | + end |
| 158 | + |
| 159 | + function testHorizontalBarPlotData(tc) |
| 160 | + fig = figure("Visible","off"); |
| 161 | + x = 1:12; |
| 162 | + y = [38556 24472 14556 18060 19549 8122 28541 7880 3283 4135 7953 1884]; |
| 163 | + barh(x,y); |
| 164 | + |
| 165 | + p = plotlyfig(fig,"visible","off"); |
| 166 | + |
| 167 | + tc.verifyNumElements(p.data, 1); |
| 168 | + tc.verifyEqual(p.data{1}, struct( ... |
| 169 | + "xaxis", "x1", ... |
| 170 | + "yaxis", "y1", ... |
| 171 | + "type", "bar", ... |
| 172 | + "name", '', ... |
| 173 | + "visible", true, ... |
| 174 | + "orientation", "h", ... |
| 175 | + "x", y, ... |
| 176 | + "y", x, ... |
| 177 | + "marker", struct( ... |
| 178 | + "line", struct( ... |
| 179 | + "color", "rgba(0,0,0,1.000000)", ... |
| 180 | + "width", 0.5, ... |
| 181 | + "dash", "solid" ... |
| 182 | + ), ... |
| 183 | + "color", "rgba(0,114,189,1.000000)" ... |
| 184 | + ), ... |
| 185 | + "showlegend", true ... |
| 186 | + )); |
| 187 | + end |
| 188 | + |
| 189 | + function testPieChartPlotData(tc) |
| 190 | + fig = figure("Visible","off"); |
| 191 | + count = [35 29 28 40 27 30 34 28 36 29 29 30 31 60 90]; |
| 192 | + label = 1:15; |
| 193 | + pie(count,label); |
| 194 | + |
| 195 | + p = plotlyfig(fig,"visible","off"); |
| 196 | + |
| 197 | + tc.verifyNumElements(p.data, 15); |
| 198 | + tc.verifyEqual(p.data{1}, struct( ... |
| 199 | + "xaxis", "x1", ... |
| 200 | + "yaxis", "y1", ... |
| 201 | + "type", 'scatter', ... |
| 202 | + "x", [-0.0196 -0.0196 -0.0761 -0.1324 -0.1883 -0.2437 -0.2984 -0.3522 -0.4049 -0.0196 -0.0196], ... |
| 203 | + "y", [0.0981 1.0981 1.0965 1.0917 1.0837 1.0726 1.0584 1.0411 1.0208 0.0981 0.0981], ... |
| 204 | + "name", '', ... |
| 205 | + "visible", true, ... |
| 206 | + "fill", 'tozeroy', ... |
| 207 | + "mode", 'lines', ... |
| 208 | + "marker", struct( ... |
| 209 | + "sizeref", 1, ... |
| 210 | + "sizemode", 'diameter', ... |
| 211 | + "size", 6, ... |
| 212 | + "line", struct( ... |
| 213 | + "width", 0.5 ... |
| 214 | + ), ... |
| 215 | + "color", "rgb(0,0,0)" ... |
| 216 | + ), ... |
| 217 | + "line", struct( ... |
| 218 | + "color", "rgb(0,0,0)", ... |
| 219 | + "width", 0.5, ... |
| 220 | + "dash", 'solid' ... |
| 221 | + ), ... |
| 222 | + "fillcolor", "rgba(62,38,168,1.000000)", ... |
| 223 | + "showlegend", false ... |
| 224 | + ), AbsTol=1e-4); |
| 225 | + end |
| 226 | + |
| 227 | + function testDoubleYAxisLinePlotData(tc) |
| 228 | + fig = figure("Visible","off"); |
| 229 | + x = linspace(0,10); |
| 230 | + y = sin(3*x); |
| 231 | + yyaxis left |
| 232 | + plot(x,y) |
| 233 | + y2 = sin(3*x).*exp(0.5*x); |
| 234 | + yyaxis right |
| 235 | + plot(x,y2) |
| 236 | + ylim([-150 150]) |
| 237 | + |
| 238 | + p = plotlyfig(fig,"visible","off"); |
| 239 | + |
| 240 | + tc.verifyNumElements(p.data, 4); |
| 241 | + tc.verifyEqual(p.data{1}, struct( ... |
| 242 | + "type", 'scatter', ... |
| 243 | + "xaxis", 'x1', ... |
| 244 | + "yaxis", 'y1', ... |
| 245 | + "visible", true, ... |
| 246 | + "name", '', ... |
| 247 | + "mode", 'lines', ... |
| 248 | + "x", x, ... |
| 249 | + "y", y, ... |
| 250 | + "line", struct( ... |
| 251 | + "color", "rgb(0,114,189)", ... |
| 252 | + "width", 0.5, ... |
| 253 | + "dash", 'solid' ... |
| 254 | + ), ... |
| 255 | + "marker", struct( ... |
| 256 | + "size", 3.6, ... |
| 257 | + "line", struct( ... |
| 258 | + "width", 0.5 ... |
| 259 | + ), ... |
| 260 | + "color", "rgb(0,114,189)" ... |
| 261 | + ), ... |
| 262 | + "showlegend", false ... |
| 263 | + ), AbsTol=1e-6); |
| 264 | + tc.verifyEqual(p.data{2}, struct( ... |
| 265 | + "type", 'scatter', ... |
| 266 | + "xaxis", 'x1', ... |
| 267 | + "yaxis", 'y2', ... |
| 268 | + "visible", true, ... |
| 269 | + "name", '', ... |
| 270 | + "mode", 'lines', ... |
| 271 | + "x", x, ... |
| 272 | + "y", y2, ... |
| 273 | + "line", struct( ... |
| 274 | + "color", "rgb(217,83,25)", ... |
| 275 | + "width", 0.5, ... |
| 276 | + "dash", 'solid' ... |
| 277 | + ), ... |
| 278 | + "marker", struct( ... |
| 279 | + "size", 3.6, ... |
| 280 | + "line", struct( ... |
| 281 | + "width", 0.5 ... |
| 282 | + ), ... |
| 283 | + "color", "rgb(217,83,25)" ... |
| 284 | + ), ... |
| 285 | + "showlegend", false ... |
| 286 | + ), AbsTol=1e-6); |
| 287 | + end |
| 288 | + |
| 289 | + function testDoubleYAxisAreaPlotData(tc) |
| 290 | + fig = figure("Visible","off"); |
| 291 | + x = linspace(0,10); |
| 292 | + y = sin(3*x); |
| 293 | + yyaxis left |
| 294 | + area(x,y) |
| 295 | + y2 = sin(3*x).*exp(0.5*x); |
| 296 | + yyaxis right |
| 297 | + area(x,y2) |
| 298 | + ylim([-150 150]) |
| 299 | + |
| 300 | + p = plotlyfig(fig,"visible","off"); |
| 301 | + |
| 302 | + tc.verifyNumElements(p.data, 4); |
| 303 | + tc.verifyEqual(p.data{1}, struct( ... |
| 304 | + "xaxis", "x1", ... |
| 305 | + "yaxis", "y1", ... |
| 306 | + "type", "scatter", ... |
| 307 | + "x", x, ... |
| 308 | + "y", y, ... |
| 309 | + "name", '', ... |
| 310 | + "visible", true, ... |
| 311 | + "fill", "tozeroy", ... |
| 312 | + "mode", "lines", ... |
| 313 | + "line", struct( ... |
| 314 | + "color", "rgba(0,0,0,1.000000)", ... |
| 315 | + "width", 0.5, ... |
| 316 | + "dash", "solid" ... |
| 317 | + ), ... |
| 318 | + "fillcolor", "rgba(0,114,189,1.000000)", ... |
| 319 | + "showlegend", true ... |
| 320 | + )); |
| 321 | + tc.verifyEqual(p.data{2}, struct( ... |
| 322 | + "xaxis", "x1", ... |
| 323 | + "yaxis", "y2", ... |
| 324 | + "type", "scatter", ... |
| 325 | + "x", x, ... |
| 326 | + "y", y2, ... |
| 327 | + "name", '', ... |
| 328 | + "visible", true, ... |
| 329 | + "fill", "tozeroy", ... |
| 330 | + "mode", "lines", ... |
| 331 | + "line", struct( ... |
| 332 | + "color", "rgba(0,0,0,1.000000)", ... |
| 333 | + "width", 0.5, ... |
| 334 | + "dash", "solid" ... |
| 335 | + ), ... |
| 336 | + "fillcolor", "rgba(217,83,25,1.000000)", ... |
| 337 | + "showlegend", true ... |
| 338 | + )); |
| 339 | + end |
| 340 | + end |
| 341 | +end |
0 commit comments