Main Content

panInteraction

Pan interaction

Since R2019a

Description

A pan interaction allows you to pan within a chart without having to select any buttons in the axes toolbar. To enable panning, set the Interactions property of the axes to a panInteraction object. When this interaction is enabled, you can pan by dragging within the chart.

To enable multiple interactions, set the Interactions property to an array of objects.

Creation

Description

example

p = panInteraction creates a pan interaction object.

example

p = panInteraction('Dimensions',d) sets the Dimensions property. Use this property to constrain panning to specific dimensions. For example, p = panInteraction('Dimensions','x') constrains panning to the x-dimension.

Properties

expand all

Dimensions to allow panning, specified as one of these values:

  • 'xyz' — Allows panning in all dimensions.

  • 'xy' — Allows panning in the x and y dimensions only.

  • 'yz' — Allows panning in the y and z dimensions only.

  • 'xz' — Allows panning in the x and z dimensions only.

  • 'x' — Allows panning in the x dimension only.

  • 'y' — Allows panning in the y dimension only.

  • 'z' — Allows panning in the z dimension only.

The Dimensions property is only supported for interactions in Cartesian axes.

Examples

collapse all

Create a surface plot. Get the current axes and replace the default interactions with the pan and data tip interactions. Then hover over the surface to display data tips. Click and drag or tap and drag to pan.

surf(peaks)
ax = gca;
ax.Interactions = [panInteraction dataTipInteraction];

Plot a set of x and y values, and adjust the x-axis limits to narrow the view of the plot. Then replace the default set of interactions with a pan interaction that is restricted to the x-dimension. Drag within the plot to pan. Notice that you cannot pan vertically.

x = linspace(-500,500,5000);
y = sin(x)./x;
plot(x,y)
xlim([-50 50])
ax = gca;
ax.Interactions = panInteraction('Dimensions','x');

Tips

In most cases, the axes have a default set of interactions which depend on the type of chart you are displaying. You can replace the default set with a new set of interactions, but you cannot access or modify any of the interactions in the default set.

Version History

Introduced in R2019a