Main Content


Ruler-pan interaction


A ruler-pan interaction allows you to pan an axis without having to select any buttons in the axes toolbar. To enable ruler panning, set the Interactions property of the axes to a rulerPanInteraction object. When this interaction is enabled, you can pan an axis by dragging it.

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




rp = rulerPanInteraction creates a ruler-pan interaction object.


rp = rulerPanInteraction('Dimensions',d) sets the Dimensions property. Use this property to constrain panning to a single axis or a subset of axes. For example, rp = rulerPanInteraction('Dimensions','x') constrains panning to the x-axis.


expand all

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

  • 'xyz' — Allows panning on all three axes.

  • 'xy' — Allows panning on the x- and y-axes only.

  • 'yz' — Allows panning on the y- and z-axes only.

  • 'xz' — Allows panning on the x- and z-axes only.

  • 'x' — Allows panning on the x-axis only.

  • 'y' — Allows panning on the y-axis only.

  • 'z' — Allows panning on the z-axis only.


collapse all

Create a surface plot. Get the current axes and replace the default interactions with the ruler-pan and data tip interactions. Then hover over the surface to display data tips. Drag any axis to pan the limits.

ax = gca;
ax.Interactions = [rulerPanInteraction dataTipInteraction];

Create x and y values, and plot them using custom x-axis limits. Replace the default set of interactions with a ruler-pan interaction that is restricted to the x-dimension. Then drag the x-axis to pan. Notice that you cannot pan the y-axis.

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


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