Main Content

Plot a Circle Using the XY Graph Block

This example shows how to plot data using the XY Graph block. The XY Graph block is an alternative configuration of the Record block that plots two input signals on an XY plot. The XY plot used by the Record block is also available in the Simulation Data Inspector. The XY Graph block has all the capabilities if the Record block, including the ability to log data to the workspace and a file.

The model computes x and y data to plot a circle using a third variable, θ. Using a polar coordinate system, you can express the equation for a circle of radius a centered on the origin as:

r(θ)=a

Converting the equation to use Cartesian coordinates results in these equations for the x and y data:

x=acos(θ)

y=asin(θ)

The model computes the x and y data using Trigonometric Function blocks. The Ramp block provides the input θ and the Constant block sets the radius of the circle. Open and simulate the model.

mdl = "XYGraphCircle";
open_system(mdl);
sim(mdl);

The XY GraphCircle model

To view the plotted results, double-click the XY Graph block.

A scatter plot of a circle plotted in the XY Graph block

You can add subplots to the layout in the XY Graph block to view the x and y data variations against time. For example, select Layouts. Then, under Overlays, select Bottom. To view the signals, click Show Signals. To plot the x signal, select the left overlay, then select the check box next to the x signal. To plot the y signal, select the right overlay, then select the y signal.

A scatter plot of a circle overlayed with a time plot of the x data in the lower left and the y data in the lower right

You can also update the styling of the data plotted on the XY plot. For example, add a connecting line and remove the data markers. Select the XY subplot. To add a connecting line to the plot, on the Format tab, under Line, click Line. To remove the markers from the plot, on the Format tab, under Markers, click Markers.

The circle plotted with a line instead of markers

The XY plot supports other analysis and visualization features, including trend lines and the ability to plot more than one series. For more information, see Visualize Simulation Data on XY Plot and Analyze Data Using XY Plot.

See Also

Blocks

Tools

Related Topics