File Exchange

image thumbnail

PlotAxisAtOrigin

version 1.0 (1.47 KB) by

This is a 2D vresion of Plot3AxisAtOrigin, which may be used to plot axis at origin.

3.21429
15 Ratings

52 Downloads

Updated

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!

Comments and Ratings (18)

nuliangju

Lukas

Lukas (view profile)

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

zhao (view profile)

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

Jan

Jan (view profile)

@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

Anael (view profile)

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

Bob (view profile)

Sam

Sam (view profile)

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!

David Polcari

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

Markus Buehren

Markus Buehren (view profile)

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
MATLAB 7.1.0 (R14SP3)
Acknowledgements

Inspired by: plot3axisatorigin

Inspired: axescenter

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today