Compose-2030 Creating Plots in OML
- Creating a plot.
- Creating a subplot.
- Get/Set the figure/axes/curve/text properties.
- Adding data into a plot.
- More 2D plot types.
- More 3D plot types.
- Using utility commands.
- Interacting with UI.
More details on each function used in this tutorial can be found in the Function Reference Guide.
Creating a Plot
In OML, data can be visualized in various forms by plotting commands, such as plot, bar, polar, surface, contour, and so on. The simplest and most-used command is plot, which creates a line plot based on the given data.
Create a Subplot
It’s useful to create a grid of plots in a single figure to compare the curves. This can be done using the commandsubplot().
Get and Set the Figure, Axes, Curve, and Text Properties
Each plotting item in OML, such as the figure, axes, curve, and text, are graphic objects, which have handles and properties associated with them. Use the command get() to query the properties and set() to change them.
Add Data into a Plot
By default, running each plotting command replaces data in the current axes, and this behavior can be changed by calling the hold() command. This command toggles/changes the “hold” state of current axes, and if turned on, plotting commands add data, instead of replace, in the current axes. Hold() takes ‘on’ or ‘off’ as an argument, to turn on or off the “hold” state of the current axes. It can be called without an argument also. In this case, it’ll toggle the state.
More 2D Plot Types
Besides the plot() command, more 2D plot commands can be used to visualize 2D data, including: line(), bar(), scatter(), area(), polar(), fill(), hist(), loglog(), semilogx(), semilogy(), and contour().
3D Plot Types
Besides the 2D plotting commands, 3D plot commands can be used to visualize 3D data, including: plot3(), scatter3(), surf(), mesh(), waterfall(), and contour3().
Plot Utility Commands
- gcf() returns current figure handle; clf() returns current figure.
- gca() returns current axes handle; cla() returns current axes.
- close() closes the current figure; close('all') closes all figures.
- ishandle() takes a number or variable and judges whether it is a handle; isfigure() takes a number or variable and judges whether it is a figure handle; isaxes() takes a number or variable and judges whether it is axes handle.
- grid() turns on/off the grids of an
axes:
x=[0:0.1:3*pi]; plot(x, sin(x)); grid;
- legend() turns on/off the legend of an axes. With string
arguments, legend() updates the legend of each
curve:
x=[0:0.1:3*pi]; plot(x, sin(x), x, cos(x)); legend('sin(x)', 'cos(x)');
- title(), xlable(),
ylabel(), zlabel() can be used to
updated corresponding
text:
x=[0:0.1:3*pi]; plot(x, sin(x), x, cos(x)); title('sin&cos curves');
- axis() can be used to set axis limits. When called
without an argument, it turns on the auto-scaling of the current axes and
returns the current axes
limits:
x=[0:0.1:3*pi]; plot(x, sin(x), x, cos(x)); axis([0 15 -2 2]);
- text() inserts some text in the axes on a specified
location:
x=[0:0.1:3*pi]; plot(x, sin(x), x, cos(x)); text(pi/2, 1,'hello');
Interacting with the User Interface
Creating and handling plots is introduced in tutorial Compose-1000. The Compose application allows you to manipulate plots in the plot view (to interactively change plot properties) but also in the Project Browser to manage plot objects and add/remove them to/from projects.
- Plots created by a script can be shown, hidden, or deleted.
- You can choose files and plots to be saved in a project file. Plots are
added into a project automatically when created, and it will prompt whether
plots should be saved in the project file or not when you save the project.
To save the project, select
From the Plot View mode:
In plot view, you can interact and manipulate the plot using the following methods:
and select a location for the project file. You are prompted
to answer if plots must be added to the project.
- Ctrl + Mouse left button dragging: Pan the plot.
- Mouse wheel rolling up/down: Zoom in/out the plot.
- If the mouse is on the X (resp. Y) axis, it will only zoom on the X (resp. Y) axis.
- Middle mouse button (mouse wheel) click: Reset plot view.
- Middle mouse button (mouse wheel) dragging: Circle zoom in plot.
- Ctrl + Middle mouse button (mouse wheel) dragging: Box zoom in plot.
- Mouse right-button click: Displays specific panel (see below).
In the plot view, you can access properties of each area by right-clicking on an element of plot, such as the curve, axes, legend, title, background, an so on.
The dialogs are dismissed by clicking elsewhere in the plot view. Here are some examples of the properties dialogs.
Curve style dialog:
Axis Style dialog: