1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2018 - 2019 - Samuel GOUGEON
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
8 // <-- INTERACTIVE TEST -->
9 // <-- TEST WITH GRAPHIC -->
10 // <-- NO CHECK REF -->
12 // unitary tests of colorbar()
13 // =============================================================================
15 // ORGANIZATION of TESTS
16 // * Open figures 0 and 10
17 // * Dock them somewhere in the desk in order to make them always visible
18 // * Execute each block of lines and see results and comments
20 // CHECKING COLORS SPLITTING AND TICKING + SKIPPED ARGUMENTS
21 // =========================================================
25 // 1.0) Matplot: implicit minU, maxU, colminmax = [umin umax]
28 Matplot([1 2 3;4 5 7]);
29 colorbar // [1 7] graduations covered by colors #[1 7].
30 // Ticks on middles of colored blocks
32 // 1.1) Matplot: colminmax = [umin umax] accordingly
34 Matplot([1 2 3;4 5 7]);
35 colorbar(1,7,-1) // [1 7] graduations covered by colors #[1 7].
36 // Ticks on middles of colored blocks
40 Matplot([1 2 3;4 5 7]);
41 colorbar(,,-1,"%6.1f") // http://bugzilla.scilab.org/14790
42 assert_checkequal(gcf().children(1).ticks_format(2), "%6.1f");
45 // 1.3) Matplot: Default colminmax = [1 Nc]
47 Matplot([1 2 3;4 5 7]);
48 colorbar(1,7) // [1 7] covered with the whole colormap.
49 // "1" at the very bottom. "7" at the very top.
51 // 1.4) Matplot: another colors range, with explicit colminmax
53 Matplot([1 2 3;4 5 7])
55 // Ticks 2.5-7.5 expected:
56 // - integer values ticked at the middle of colors blocks
57 // - other .5 values ticked at the blocks separations
63 // Sgrayplot (Fec) : all colors used
64 // ---------------------------------
66 z = cos(2*%pi*x)'*sin(2*%pi*x);
67 // 2.0) Default umin = minU, umax = maxU, colminmax = [1 Nc]
70 gcf().color_map = jetcolormap(n);
72 contour(x,x,z,[-0.5 0 0.5]);
73 gce().children.children(1:2:$-1).foreground=-1; // contours in black
75 // * 4 colors of equal spans
76 // * "-1" tick at the very bottom of the scale
77 // * "1" tick at the very top
79 // * The contours levels must be at the right levels on the color bar
81 // 2.1) Default umin = minU, umax = maxU, colminmax = [1 Nc] (same as above)
84 gcf().color_map = jetcolormap(n);
86 contour(x,x,z,[-0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8]);
87 gce().children.children(1:2:$-1).foreground=-1; // contours in black
88 colorbar; // Same as above, with n = 10
89 // Nice subticks, at blocks middles & blocks limits
91 // Sgrayplot (Fec) : partial colors range: 8 colors used over 20
92 // -------------------------------------------------------------
93 // 2.2) umin=minU and umax=maxU, covered by a subrange of colors
96 gcf().color_map = jetcolormap(20);
97 Sgrayplot(x, x, z,colminmax=[3 n+2]);
98 contour(x,x,z,[-0.75 -0.5 -0.25 0 0.25 0.5 0.75]);
99 colorbar(-%inf,%inf,[3 n+2]);
100 // * The contours levels must be at the right levels on the color bar
102 // 2.3) Explicit umin and umax, with saturation for z values out of [umin, umax]:
104 gcf().color_map = jetcolormap(20);
105 Sgrayplot(x, x, z, zminmax = [-0.6 0.8], colminmax = [5 11]);
106 contour(x,x,z,[-0.6 -0.4 -0.2 0.2 0.4 0.6]);
107 colorbar(-0.6, 0.8,[5 11]);
108 // Sgrayplot zminmax & colminmax matches the colorbar() ones
109 // The bar is correct, wrt contours levels
114 function [zz, zz1] = plotSphere()
117 deff("[x,y,z]=sph(alp,tet)",["x=r*cos(alp).*cos(tet)+orig(1)*ones(tet)";..
118 "y=r*cos(alp).*sin(tet)+orig(2)*ones(tet)";..
119 "z=r*sin(alp)+orig(3)*ones(tet)"]);
120 [xx,yy,zz] = eval3dp(sph,linspace(-%pi/2,%pi/2,40),linspace(0,%pi*2,20));
121 [xx1,yy1,zz1] = eval3dp(sph,linspace(-%pi/2,%pi/2,40),linspace(0,%pi*2,20));
123 cc1 = (xx1-orig(1)+zz1/r+2)*32;
125 plot3d1([xx xx1],[yy yy1],list([zz,zz1],[cc cc1]),theta=70,alpha=80,flag=[5,6,3])
126 gcf().color_map = hotcolormap(128);
129 // 3.0) Implicit min(u), max(u), on the whole color map
132 colorbar; // colorbar [black orange white] on u=[min(u)=-0.3, max(u)=0.3]
134 // 3.1) Implicit partial colors range, according to u-range
137 colorbar(0.0, 0.15, -1); // [cmin cmax]/Nc matches the U relative range
138 // Colors/Values should match on figures 0 and 10
140 // 3.2) umin & umax such that the relative ranges [umin, umax] and colminmax match
142 colorbar(,,[64 128]); // graduations on [0 , 0.3]
143 // Colors/Values should match on figures 0 and 10
145 // 3.3) umin & umax set according to partial colormap as fraction / whole u-range
147 colorbar(,,[2.97 5]/6); // ticks on [0, 0.2]
148 // colors in [orange, yellow] must match figure #10 ones
150 // 3.4) after graypolarplot()
154 // Values from 30 to 137. Direct colors = full color map = dark red to white.
158 function plotSample()
161 gcf().color_map = jetcolormap(200);
162 plot3d(t,t,sin(t)'*cos(t));
168 // 4.0) Bar graduated from minU=-1 to maxU=1 with the full colormap
173 // 4.1) Bar graduated from umin=1 to umax=2 with the full colormap
178 // 4.2) Bar graduated from -0.3 to 0.5 with the corresponding relative colors range
180 colorbar(-0.3,0.5, -1); // Colors/Values should match on figures 0 and 10
182 // 4.3) Bar graduated from minU=-1 to maxU=1, with colors #101 to #200
184 colorbar(-%inf,%inf,[101 200]); // [0 1] => [-1 1]
186 // 4.4) umin & umax range set to match the relative colors one
188 colorbar(,,[100 200]); // graduations from 0 to 1
189 // Colors/Values should match on figures 0 and 10
191 // 4.5) Same as above, with colors given as fractions inside the whole colormap
193 colorbar(,,[0.6 0.8]); // values from 0.2 to 0.6
195 // 4.6) Same as 4.4), with colors given with $
197 colorbar(,,[$/2 $]); // values from 0 to 1
202 twinkle(gce()) // The colorbar of the last test must twinkle