Kahibaro
Discord Login Register

Using plottools and Interactive Editing

Overview of plottools and Interactive Editing

MATLAB provides graphical tools that let you edit plots directly with the mouse, without writing or changing code. These tools are useful when you want to quickly fine tune a figure, explore data interactively, or learn which properties affect a plot.

This chapter focuses on the classic plottools interface and a few related interactive features in standard figure windows.

Opening plottools

You can open the plot tools for the current figure in several ways. The most direct way from the Command Window is to use the plottools command.

For example, create a simple plot first.

x = 0:0.1:2*pi;
y = sin(x);
plot(x, y)

Then open the tools.

plottools

If a figure is already open, plottools attaches three main panels to that figure: the Figure Palette, the Plot Browser, and the Property Editor. You can close them again with the same command.

plottools off

You can also open individual parts. For example, to open only the Property Editor use:

propertyeditor

These tools work on the current figure, which you can make current with figure if you have multiple figures open.

The Figure Palette

The Figure Palette is a panel that helps you add new plots, axes, and common annotations to a figure with drag and drop actions.

Once you open plottools, the Figure Palette is usually on the left side of the figure window. It is divided into several areas.

At the top you see a list of workspace variables. Numeric vectors and matrices appear here. You can drag these variables directly onto an axis area in the figure and MATLAB will create an appropriate plot. For example, dragging x and y into an empty figure will create a line plot. Dragging a single vector onto an existing axis can add it as a new line.

Below the variables list there are quick buttons and controls for creating axes and for adding typical plot types based on selected variables. This lets you build figures interactively without typing functions such as plot, bar, or scatter.

The Figure Palette also lets you add axes to a figure. You can insert a new axes region, then drag data onto it. This is a convenient way to create multi-axes figures without explicitly calling subplot functions.

The Plot Browser

The Plot Browser shows the structure of the current figure. It lists all axes and the graphics objects they contain. This panel is very useful when your figure has several plots, lines, or annotations.

After you open plottools, the Plot Browser is usually docked on the right side of the figure window. Its tree view shows items such as the figure itself, each axes, and the children of each axes, for example individual line objects.

You can use check boxes next to entries to quickly toggle the visibility of each plot element. This is helpful when you want to compare different data series by hiding and showing them without deleting them.

Selecting an item in the Plot Browser also selects it in the figure. This makes it easy to choose exactly which line or object you want to edit when several items overlap visually. Once an object is selected, its editable properties appear in the Property Editor.

The Property Editor

The Property Editor is the main interactive panel for changing how objects look. It provides a graphical interface to common properties of figures, axes, and plot objects such as lines, markers, and patches.

When you select an object, such as a line, the Property Editor displays controls specific to that type of object. For a line, you will see options for color, line style, marker style, marker size, and similar visual settings. Changing these settings in the panel updates the figure immediately.

The Property Editor is organized into sections. When an axes is selected, you see controls for axis limits, ticks, grid lines, and background color. When the figure itself is selected, you can change properties such as the figure name, size, or color.

Although the Property Editor only shows commonly used properties, it provides a gentle way to learn the property names. When you adjust a setting interactively, MATLAB is changing the same properties you can change from code. You can later reproduce the same changes with commands that use set or dot notation such as h.LineWidth = 2.

Selecting and Editing Objects with the Mouse

Interactive editing is based on selecting objects in the figure and then modifying them. You can select an object directly in the figure window by clicking on it. When selected, the object may show handles or highlight markers to indicate selection.

After selecting a line, you can often right click to open a context menu. This menu typically contains options to change color, line style, marker type, or copy and delete the object. For axes, the context menu often includes options related to zoom, pan, grid lines, and axes limits.

You can drag axes and annotations to reposition them. For axes, you can drag the borders to resize the plotting area. For text annotations or arrows, you can drag the objects to the desired location.

If you resize the figure window itself, MATLAB automatically adjusts its contents according to their layout settings. You can refine that layout by manually dragging axes or objects into the exact arrangement you want.

Editing Text, Labels, and Legends Interactively

Many text elements in a figure can be edited directly. This includes axis labels, titles, and legend entries.

To edit axis labels or the title, you can double click the existing text in the figure. MATLAB displays a small text box where you can type new content. When you press Enter or click outside the box, the change is applied.

If a figure has a legend, you can double click a legend entry to edit the label text. This is useful when you want to give more descriptive names than the default ones derived from the plotted variables.

The Property Editor also exposes text settings. When a text object such as a label or title is selected, you see font settings, color, alignment, and interpreter options. You can adjust these interactively to improve readability of the plot.

Working with Interactive Tools: Zoom, Pan, and Data Cursor

In addition to plottools panels, MATLAB figure windows include several built in interactive tools that work from the toolbar or menus.

The zoom tool allows you to increase or decrease the visible region of an axes. You can click the magnifying glass icons in the figure toolbar or call zoom from the command line. With zoom mode active, clicking in the axes zooms in, while right clicking or using the toolbar can zoom out. You can also drag out a rectangle to zoom into a specific region.

The pan tool lets you shift the visible region without changing the zoom level. With pan mode active, you can click and drag inside the axes to move the view horizontally or vertically.

The data cursor tool is especially helpful for inspecting values. When you activate it, you can click on the plotted data to create small data tips. Each data tip shows the coordinates of that point, for example the x and y values for a line plot. You can move a data tip along a curve and see how the values change. This is a fast way to read off values without writing any code.

These tools operate on the displayed data and do not change the underlying variables in the workspace. They affect only how the plot is viewed.

Recording Interactive Changes as Code

Interactive editing is most useful when you want to explore and experiment. However, when you are satisfied with the appearance of a figure, you often want to reproduce the same style from code.

A practical approach is to use interactive tools to find settings that you like, then inspect the resulting object properties from the Command Window. For example, after selecting a line and changing its appearance with the Property Editor, you can obtain a handle to that line from the Plot Browser or by using gco to get the current object.

For example:

h = gco;
get(h)

The output lists properties and their values. You can then write equivalent code statements such as:

h.LineWidth = 2;
h.Color = [0 0.5 0];
h.Marker = 'o';

This process lets you turn interactive experimentation into reproducible code. You do not have to guess the property names or valid values, because the interactive tools have already set them for you.

When to Use plottools and When to Use Code

Interactive editing is very convenient for one time plots, quick exploratory work, or when you are still learning which settings control the appearance of plots. It is also helpful when adjusting complex figures created by someone else.

For automated scripts, functions, or repeated reports, it is better to apply styling through code so that figures are created consistently. In such cases, you can still rely on plottools during development to find settings that you then copy into your script.

Using both approaches together provides a comfortable workflow. You experiment and adjust visually, then convert the final choices into code for future reuse.

Key points to remember:

  1. Use plottools to open interactive panels for editing plots in an existing figure.
  2. The Figure Palette lets you drag workspace variables to create plots and axes.
  3. The Plot Browser lists axes and graphics objects and lets you toggle visibility and select items.
  4. The Property Editor changes visual properties of selected objects such as lines, axes, and text.
  5. Use zoom, pan, and data cursor to explore data without changing your code or variables.
  6. After interactive editing, inspect object properties to reproduce the same changes with MATLAB code.

Views: 3

Comments

Please login to add a comment.

Don't have an account? Register now!