File Exchange

image thumbnail

axes0

version 2.0.0.0 (14.3 KB) by Delyle Polet
Easily plot the x and y axes through the origin

3 Downloads

Updated 14 Apr 2016

View License

SYNTAX:
axes0
axes0('PropertyName',propertyvalue,...)
h = axes0(...);
PROPERTIES: (Name-value pairs)
'origin' - Position of the origin label
'bottomleft'(default)|'topleft'|'topright'|'bottomright'
'southwest'|'northwest'|'northeast'|'southeast'|'none'
'XTickLabelPos' - Position of the x-axis tick labels with respect to the axis

'bottom'(default)|'top'
'YTickLabelPos' - Position of the y-axis tick labels with respect to the axis
'left'(default)|'right'
'XLabelPos' - Position of the x-axis label with respect to the axis
'topright (default)'|'bottomright'|'topleft'|'bottomleft'
'firstquad'|'secondquad'|'thirdquad'|'fourthquad'
'left'|'right'
'YLabelPos' - Position of the y-axis label with respect to the axis
'topright (default)'|'bottomright'|'topleft'|'bottomleft'
'firstquad'|'secondquad'|'thirdquad'|'fourthquad'
'top'|'bottom'
'ticks' - Specify whether to plot the tick markers
'on'(default)|'off'|logical
Legacy properties (still work but have been replaced):
'xlabels' - Position of the x-axis labels with respect to the axis
'bottom'(default)|'top'
'ylabels' - Position of the y-axis labels with respect to the axis
'left'(default)|'right'
If the following is called:
h = axes0('PropertyName',propertyvalue,...)
The function returns handles in the structure h. The following fields are returned:
xt = handle of the x tick labels
yt = handle of the y tick labels
o = handle of the origin label
xl = handle of the x axis label
yl = handle of the y axis label
All handles are text objects and any text object properties can
be modified using set(h.field,'PropertyName',propertyvalue) after
axes0 has been called.

EXAMPLES:
Example 1 - Default settings:

figure;
x = linspace(-2,2,101);
plot(x,2*x.^3-3*x+1);
xlabel('x')
ylabel('y','Rotation',0)

axes0

Example 2 - Some Name-Value pairs for better aesthetics:

figure;
plot(x, x.^2-2*x-1);
xlabel('t')
ylabel('f(t)','Rotation',0)
axes0('origin','topright','xticklabelpos','top','yticklabelpos','right',...
'xlabelpos','fourthquad','ylabelpos','secondquad');

Example 3 - Modify labels using text object properties:

figure
x = linspace(-2,2,101);
plot(x,2*x.^3-3*x+1);
h = axes0;
set(h.xt,'FontSize',15,'color','b')
set(h.o,'FontSize',15,'color','r','fontweight','bold')

Example 4 - axes0 inherits most properties of the original axis

figure;
x = linspace(-1,2,101);

plot(x,x)
xlabel('x','fontsize',16)
ylabel('$y(x)$','Rotation',0,'fontsize',19,'color','b','interpreter','latex')
set(gca,'fontsize',11,'fontweight','bold','fontname','times','fontangle','italic')

axes0

--
ACKNOWLEDGEMENTS
The following post on Stack Overflow inspired this function:
http://stackoverflow.com/a/2945107/4941405

Note: As mentioned in the comments, most of the functionality of axes0 was built directly into the axis object in MATLAB 2015b. See: http://www.mathworks.com/help/matlab/creating_plots/display-axis-lines-through-origin.html

Users of earlier versions of MATLAB (or users who want a quick way to label the origin) may find the present function useful

Comments and Ratings (2)

Nagy Noémi

Sadly, I have this error:
Error: File: axes0.m Line: 191 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [.

What can be a solution?

Very impressive, Delyle!

Note that users of R2014b and newer releases can take advantage of this capability being built directly into the axes object. This is controlled by the XAxisLocation and YAxisLocation properties, as shown here:

http://www.mathworks.com/help/matlab/creating_plots/display-axis-lines-through-origin.html?searchHighlight=origin

Updates

2.0.0.0

-Update to submission title

2.0.0.0

- Axis labels and their properties will be inherited by axes0
- The location of the axis labels can be specified with name value pairs
- Output is a structure of object handles
- Many original axis properties are inherited

1.1.0.0

- Original axis font size is now preserved
- Switched from using '+' markers to using patch lines as ticks- looks better
- Original axis tick size is preserved

1.0.0.0

Added image to submission, slight change to description format

1.0.0.0

Formatted description

1.0.0.0

Updated the description

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