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 of 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, $\theta$. Using a polar coordinate system, you can express the equation for a circle of radius $a$ centered on the origin as:

$$ r(\theta) = a$$

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

$$x = a \cos (\theta)$$

$$y = a \sin (\theta)$$

The model computes the $x$ data and the $y$ data using Trigonometric Function blocks. The Ramp block provides the input, $\theta$, and the Constant block sets the radius of the circle.

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

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

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

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 an XY Plot and Analyze Data Using the XY Plot.

See Also



Related Topics