Main Content

Create Plot

Interactively create and explore visualizations in the Live Editor

Description

The Create Plot task lets you interactively create and explore visualizations for your data. Choose visualizations from a list of categories or let the task recommend them based on your workspace variables. The task automatically generates MATLAB® code and adds labels to the generated visualization.

Using this task, you can:

  • Create a plot by selecting variables and a chart type.

  • Explore different visualizations of the same data. Select some variables first, then try selecting different chart types.

  • Explore different data in the same visualization format. Select the chart type first. The task will prompt you for data.

  • Combine multiple plots. Overlay or combine multiple visualizations by clicking on the Add tab.

  • Customize the appearance of your plot. For example, you can change the marker symbol for line charts and the arrangement of bars for bar charts.

For a list of all the types of plots and the functions to generate them programmatically, see Types of MATLAB Plots.

To create linear analysis plots with dynamic system models, see the Create Plot (Control System Toolbox) Live Editor task reference page.

Open the Task

To add the Create Plot task to a live script in the MATLAB Live Editor:

  • On the Live Editor tab, click Task and select the Create Plot icon Create Plot task icon.

  • In a code block in the live script, type a relevant keyword, such as such as viz, visualize, create, or hold. Select Create Plot from the suggested command completions.

  • In a code block in the live script, type the name of a charting function, such as plot, bar, or contour. Select Create Plot from the suggested command completions. When you add the task using this method, then MATLAB automatically selects the corresponding chart type in the Select visualization section of the task.

Examples

expand all

Create a visualization for a data set and customize visualization parameters with Create Plot.

Read the sample data patients.mat. The file contains 10 columns of data representing fictional medical patient information.

load patients

Visualize the relationship between the Age and Diastolic variables with a scatter plot. First, create a scatter plot by adding the Create Plot task to your live script and specifying the desired visualization as a scatter plot.

Then, select the data for the plot by setting the X menu item to the Age variable and setting the Y menu item to the Diastolic variable.

Next, view the optional visualization parameters by opening the Select optional visualization parameters task section. Then, customize the scatter plot markers by setting the Marker symbol menu item to the + symbol.

The resulting visualization contains a scatter plot of Age vs. Diastolic with a + marker for each data point.

To see the code that this task generates, expand the task display by clicking Small arrow pointing down at the bottom of the task parameter area.

Live Task
% Create scatter of Age and Diastolic
s2 = scatter(Age,Diastolic,"Marker","+","DisplayName","Diastolic");

% Add xlabel, ylabel, title, and legend
xlabel("Age")
ylabel("Diastolic")
title("Age vs. Diastolic")
legend

Figure contains an axes object. The axes object with title Age vs. Diastolic contains an object of type scatter. This object represents Diastolic.

Overlay multiple plots into a single visualization with Create Plot.

Read the sample data patients.mat. The file contains 10 columns of data representing fictional medical patient information.

load patients

Visualize the relationship between the Age and Diastolic variables with a scatter plot. First, create a scatter plot by adding the Create Plot task to your live script and specifying the desired visualization as a scatter plot.

Then, select the data for the plot by setting the X menu item to the Age variable and setting the Y menu item to the Diastolic variable.

The resulting visualization contains a scatter plot of Age vs. Diastolic.

Live Task

Figure contains an axes object. The axes object with title Age vs. Diastolic contains an object of type scatter. This object represents Diastolic.

Next, visualize the relationship between the Age and Systolic variables with a scatter plot. First, overlay another plot by clicking the Add tab below the existing task parameter section.

Then, select the data for the plot by setting the Y menu item to the Systolic variable.

The resulting visualization contains multiple scatter plots in the same axes, Age vs. Systolic and Age vs. Diastolic.

To see the code that this task generates, expand the task display by clicking Small arrow pointing down at the bottom of the task parameter area.

Live Task
figure
% Create scatter of Age and Diastolic
scatter(Age,Diastolic,"DisplayName","Diastolic");

hold on
% Create scatter of Age and Systolic
scatter(Age,Systolic,"DisplayName","Systolic");
hold off

legend

Figure contains an axes object. The axes object contains 2 objects of type scatter. These objects represent Diastolic, Systolic.

Some plotting functions, like surf, accept more than one input configuration. Customize the configuration of a visualization to fit the data with Create Plot.

Generate the data to be plotted using the peaks function.

Zvar = peaks;

Visualize the generated data with a surface plot. First, create a surface plot by adding the Create Plot task to your live script and specifying the desired visualization as a surface plot.

Then, select the appropriate configuration for the generated data. Because the data is contained within one array Zvar, set the Configuration menu item to Specify Z and Color. As a result, surf only requires one data input, Z.

Next, visualize the data by setting the Z data input menu item to the Zvar variable.

The resulting visualization shows the surface created by the Z data, where the Zvar variable defines by default both the height of the surface and the surface colors.

To see the code that this task generates, expand the task display by clicking Small arrow pointing down at the bottom of the task parameter area.

Live Task

Figure contains an axes object. The axes object with title Zvar contains an object of type surface.

Related Examples

Tips

  • To interactively customize the text of titles, labels, and legends, use the options in the Figure tab.

Version History

Introduced in R2021a

expand all

See Also

Functions

Live Editor Tasks