File Exchange

image thumbnail

PlotAxisAtOrigin

version 1.0.0.0 (1.47 KB) by Shanrong Zhang
This is a 2D vresion of Plot3AxisAtOrigin, which may be used to plot axis at origin.

63 Downloads

Updated 22 Mar 2006

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

PlotAxisAtOrigin Plot 2D axes through the origin. It is a 2D version of Plot3AxisAtOrigin written by Michael Robbins. Have fun!

Cite As

Shanrong Zhang (2020). PlotAxisAtOrigin (https://www.mathworks.com/matlabcentral/fileexchange/10473-plotaxisatorigin), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)

Simpler Method:

set(ax,'XAxisLocation','origin')
set(ax,'YAxisLocation','origin')

ahmed wally

when i used this function and i need to put labels of axis as following in code:
clc
clear
syms x y
x=linspace(-5,5);
y=-3*x+8;
PlotAxisAtOrigin(x,y)
xlabel('x')
ylabel('y')
title('f(x)=y=-3*x+8')

,labels doesn`t appear .why?

nuliangju

Lukas

Why would you not just ask for the axis handle and skip the plot section? Then the user could plot whatever he wants, however he wants, and then apply the axes at origin? Then you could for example also preserve x-and ylabels (or rewrite them)

Hello, I´m not really familar with Matlab but can somebody tell me how to use this file ? Matlb gives me this Error note:

Error: Function definitions are not permitted in this context.

thx

Dear Shanrong Zhang,

please add output H=PlotAxisAtOrigin(x,y),
along with a slight change in the second active line: H=plot(x,y);

It allows handling of the figure:
function H=PlotAxisAtOrigin(x,y)
%
% Example:
% x = -2*pi:pi/10:2*pi;
% y1 = sin(x);
% y2 = cos(x);
% y = [y1;y2];
% H=PlotAxisAtOrigin(x,y);
% H(1).LineWidth = 3;
% H(2).Marker = '*';
% H(2).Color = 'm';
%

% PLOT
if nargin == 2
H=plot(x,y);
%--contunue as in your original code ----

works just as needed. Thank a lot!

zhao

when x and y doesn't contain zero , for example x=5:0.1:10; y=2*x . the function will not work

Jan

@Anael:

- Hide in comment line containing set(gcf,'color','w')

@Markus Buehren:
- It doesn't work because "Axes in origin" are actually lines in regular axes, which are hidden.

I'm thinking of writing function AxesToOrigin based on this function...

Anael

Great function!
2 comments though:
-I don't like that it changes the background color.
-I wish it wouldn't need to take any arguments.

Bob

Sam

Hello, I can not understand how to apply this to my code. I want to shift the current origin to (0,0) from (-0.3, 0) but the -y axis should not appear. My code is:

% Plot for lambda = 0.5

n = 30;

dc1 = 1/30*(0.5*66+0.5*62);
dc2 = 1/30*(0.5*57+0.5*55);

dn1 = 1/30*(0.5*40+0.5*30);
dn2 = 1/30*(0.5*35+0.5*20);
dn3 = 1/30*(0.5*20+0.5*27);

e = -0.3:0.01:0.3;


bc1 = 30*dc1*(1+(dc1./(10+e)));
bc2 = 30*dc2*(1+(dc2./(10+e)));

bn1 = 30*dn1*(1+(dn1./(2+e)));
bn2 = 30*dn2*(1+(dn2./(2+e)));
bn3 = 30*dn3*(1+(dn3./(2+e)));


plot(e, bc1, 'g')
hold all
plot(e, bc2, 'r')
hold all
plot(e, bn1, 'b')
hold all
plot(e, bn2, 'y')
hold all
plot(e, bn3, 'black')

set(gca,'XTick',-0.3:0.1:0.3)

set(gca,'XTickLabel',{'-0.3','-0.2','-0.1','0','0.1', '0.2', '0.3'})

ylim([0 90]);
xlim([-0.3 0.3]);

title('BED Plots for Organs');
xlabel('Epsilon range of alpha/beta');
ylabel('BED');

%Thank you very much!

Hi this is great but what do I do if I want to add axis labels?

zhang yanyu

chen Jian

Charles

I tried it. Works fine for me. Exactly what I wanted. Thanks for sharing

Christian

Sorry, but I think this package is not very useful. On the first view it looks nice, but the axis will not change when zooming in etc.

Markus

guillaume mille

Jinwei Gu

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: plot3axisatorigin

Inspired: axescenter