File Exchange

image thumbnail


version (799 Bytes) by Anne Urai
Offset axes, mimicks Seaborn's 'despine' option for plotting


Updated 09 Nov 2016

View Version History

View License

In Python/Seaborn, there is the option to offset the x and y axis at the origin. This 'despine' pulls the x-axis down a bit, and the y-axis left, so that data that are close to either one become more visible. This function mimics the behaviour in a matlab plot, by changing the axis limits and covering the origin of the axes with a white line.

Cite As

Anne Urai (2021). offsetAxes(ax) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (7)

Tuan Pham

Hi Anne, your function is super helpful.
On a side note, I was having trouble with log scale when using this so I tried modifying your code to adapt that in, as well as with the option to modify the offset factor, as well as the option to include axes handle vectors/all axes in a given figure handle.

Matthew Cooper

You need to add the solution for dealing with x- and y-minor ticks provided in the comment section from the stack overflow answer that inspired your function. However, note that the comment has an error. The error is in the statement that deals with the y-axis minor ticks. To address the error you need to adjust the row index used to remove the y-axis minor ticks from the value 1 to the value 2. The value 1 is correct for the x-axis minor ticks but not y-axis. Specifically, ax.YAxis.MinorTickChild.VertexData(:,ax.YAxis.MinorTickChild.VertexData(1,:)<0) = [] needs to be changed to ax.YAxis.MinorTickChild.VertexData(:,ax.YAxis.MinorTickChild.VertexData(2,:)<0) = []. Also, instead of <0 you could define a variable for the min xtick value and min ytick value and use those min values instead of 0 (i.e. within the function resetVertex)

Mallavi Sinha


Pierre Morel

Hi Anne, I was just looking into the possibility to integrate such functionality in gramm (I like the look!), and I convinced myself that there should be a cleaner way of doing this, without white lines/boxes. A trip to undocumentedmatlab and a few minutes later I found that in recent Matlab versions you can actually shorten axes lines by changing values in a.XRuler.Axle.VertexData and a.YRuler.Axle.VertexData. Additional hidden properties can be read with fieldnames(struct(a.YRuler.Axle))



MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired by: plotboxpos

Inspired: despline

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!