
| Lesson
1 Lesson 2 Lesson 3 Lesson 4 Lesson 5 Lesson 6 Lesson 7 Lesson 8 Lesson 9 Lesson 10 Lesson 11 Lesson 12 Lesson 13 Lesson 14 Lesson 15 Lesson 16 Lesson 17 Lesson 18 Lesson 19 |
Lesson 9 Axis, Plot, and ColorBarzeAxis, zePlot, and zeColorBar are extended objects designed to facilitate scientific and business plots. The zeColorBar object is especially useful for a contour plot and can be drawn as either a gradient type or a discrete type. In a contour plot, you may want place contour lines of a single color on gradient-filled image or use discrete colors to distinguish data in different ranges. These two types of color bar are very handy for such applications. The position of a colorbar refers to the global (or screen) coordinate. If the height of a color bar is larger then the width, the color bar will be drawn vertically; otherwise horizontally.
require("register")
render, scene, node, colorbar, font
= zeGrf.new("render" ,"scene", "node", "colorbar", "font")
render:add(scene)
scene:set{node = node}
node:add(colorbar)
colorbar:font(font)
colorbar:fontsize(16)
colorbar:set{position = {0.1, 0.4, 0.8, 0.05}, interpolation = 2}
--We add three key colors and use the interpolation
--function of colorbar to generate the rest.
colorbar:add(0, 1, 0, 0)
colorbar:add(6, 0, 1, 0)
colorbar:add(12, 0, 0, 1)
render:tofile("colorbar1.png")
colorbar:set{gradient = false}
render:tofile("colorbar2.png")
colorbar1.png and colorbar2.png The zeAxis object can be used as an x-axis, a y-axis, a z-axis, or a second axis of x, y, or z. Axis ticks always point toward their labels. If the axis is at the bottom of a drawing plane, tick labels and the axis label are under the axis; otherwise they are above the axis. Similarly, labels are on the left for a left axis and on the right for a right axis. Customizing axis labels and its ticks is easy with zeGraph:
require("register")
render, scene, node, axis, font
= zeGrf.new("render" ,"scene", "node", "axis", "font")
render:add(scene)
scene:set{node = node}
node:add(axis)
node:scale(0.9, 0.9, 1)
axis:font(font)
axis:fontsize(16)
axis:set{axis = "x", linewidth = 2, color = {0, 0, 1, 1},
label = "X", range = {0, 100}, tickmarks = {0, 20, 5}, ticklength = 2}
--Tick labels generated automatically
render:tofile("axis1.png")
--Customize tick labels and align them between ticks.
axis:set{axis = "x", ticklabels = {"|1990|1991|1992|1993|1994|", 1}}
render:tofile("axis2.png")
axis1.png and axis2.png The zePlot merely redefine the global coordinate so that you can layout your objects in the view easily and properly. There is no difference between a 2D plot and a 3D plot - a 2D plot is just a 3D scene being viewed straight from the positive z-axis. Here is a simple 2D plot:
require("register")
render, scene, node, plot, line, xyz, font
= zeGrf.new("render" ,"scene", "node", "plot", "line", "vertex", "font")
render:add(scene)
scene:set{node = node}
node:add(plot)
plot:font(font)
plot:fontsize(14)
plot:add(line)
plot:scale(0.6, 0.6, 1)
plot:set{axis = "x", color = {0, 0, 1, 1}, label = "X-axis",
range = {0, 100}, tickmarks = {0, 20, 5}}
plot:set{axis = "y", color = {1, 0, 0, 1}, label = "Y-axis",
range = {-10, 50}, tickmarks = {-10, 10, 5}}
line:set{vertex = xyz, solid = 2}
xyz:add(0, -10, 0)
xyz:add(100, 50, 0)
render:tofile("plot.png")
plot.png The axes in the plot does not look nice. Don't worry. Axes are place in the center of a plot by default. There are two options for relocating axes through the set() function: anchor and offset. At the moment, let's do it by the simple way, i.e., replacing plot:set{..} by
plot:set{axis = "x", color = {0, 0, 1, 1}, label = "X-axis",
range = {0, 100}, tickmarks = {0, 20, 5}, anchor = {0, -1, 0}}
plot:set{axis = "y", color = {1, 0, 0, 1}, label = "Y-axis",
range = {-10, 50}, tickmarks = {-10, 10, 5}, anchor = {-1, 0, 0}}
The option anchor={xf, yf, zf} will move a axis left-right, up-down, and front-back in the global coordinate system according to the three factors. For the x-axis, anchor={0, -1, 0} moves it along the global y-axis down to the bottom edge of the plotting area, which is the scaled viewport of the scene. |