3.0

3.0 | 1 rating Rate this file 35 downloads (last 30 days) File Size: 2.67 KB File ID: #22333

Centered coordinate axes in 2D plots

by Johan Carlson

 

05 Dec 2008

Code covered by BSD License  

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

Download Now | 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)
Zip File Content  
Other Files centeraxes.m,
centeraxes_test.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
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

Please login to add a comment or rating.
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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com