axes0

Easily plot the x and y axes through the origin
590 descargas
Actualizado 14 abr 2016

Ver licencia

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

Citar como

Delyle Polet (2024). axes0 (https://www.mathworks.com/matlabcentral/fileexchange/54326-axes0), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2015a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Line Plots en Help Center y MATLAB Answers.
Etiquetas Añadir etiquetas

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
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
-Update to submission title

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
Updated the description
Formatted description