3.5

3.5 | 2 ratings Rate this file 33 Downloads (last 30 days) File Size: 2.67 KB File ID: #22333
image thumbnail

Centered coordinate axes in 2D plots

by Johan Carlson

 

05 Dec 2008 (Updated 21 Nov 2009)

Takes the current coordinate axes (with ticks and labels) and draws new ones centered at the origin.

| Watch this File

File Information
Description

MATLAB does not have any built-in functionality for centering the coordinate axes around the origin. This tool is a first fix for solving this. An example script is included showing how to use the function.

Tested on MATLAB 2007b. Works fine, as long as the figure is not resized after the function is called.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
13 Jan 2009 John Hughes

Pretty decent. Doesn't work in cases where you have multiple axes, as you sometimes get with

plot(foo)
hold on
plot(bar)
plot(baz)
hold off

But otherwise, it works pretty darned well. One suggested improvement: allow an option for what "center" to use, so that I could have x- and y-axes intersecting at (-1, 2), if I so chose.

14 Jan 2009 Johan Carlson

Thank you John!

The option of where to put the center is a simple fix, and I'll definitely deal with that. The other issue is more serious, and unfortunately slightly harder to solve. Nevertheless, I'll give it a go.

Another limitation at the moment is that the tick marks and arrowheads tend to scale if the image is resized after the call to centeraxes.

Anyway, thanks for the feedback.

/Johan

20 Nov 2009 Mario Liverpool

Thank u Johan, I downloaded "centeraxes", it solved my problem.
How do I get the axes ticked from -1 to 1 please? now it's ticked only from -0.9 to 0.9.
Thanks again
Mario

21 Nov 2009 Johan Carlson

Mario,
I deliberately removed the end tick labels in on the axes, simply because I didn't think it looked so good. It appeared that changing this takes a bit of fixing of the code to make the arrowheads appear in the right place. Anyway, I'm on it, and I'll post a new version in a couple of days.

/JC

09 May 2011 Gabriel Ruiz  
Please login to add a comment or rating.
Updates
21 Nov 2009

Changed the x axis and y axis tick labeling so that it now includes also the end points. As a consequence, the axes are now 10% longer in order to make room for the arrowheads.

Tag Activity for this File
Tag Applied By Date/Time
plot Cristina McIntire 05 Dec 2008 15:25:52
plotting Cristina McIntire 05 Dec 2008 15:25:52
axes Cristina McIntire 05 Dec 2008 15:25:52
graph Cristina McIntire 05 Dec 2008 15:25:52
origin Cristina McIntire 05 Dec 2008 15:25:52
plotting Johan Carlson 05 Dec 2008 15:26:06
axes Johan Carlson 05 Dec 2008 15:26:06
graph2d Johan Carlson 05 Dec 2008 15:26:06
axes maria martinez 10 Jun 2009 05:30:11

Contact us at files@mathworks.com