Change Y-Axis position to desired origin?

Hi,
could someone help me how I can change origin point of y axis to (0-20) point. In fact I want to shift Y axis to point (0-20) but I don't have any idea.
hold on
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
origin = (0-20);
n= ["-240-260";"-220-240";"-200-220";"-180-200";"-160-180";"-140-160";"-120-140";"-100-120";"-80-100";"-60-80";"-40-60";"-20-40";"0-20";"0+20";"+20+40";"+40+60";"+60+80";"+80+100";"+100+120";"+120+140";"+140+160";"+160+180";"+180+200";"+200+220";"+220+240"];
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.032258064516129,0.548387096774194,0.387096774193548,0.032258064516129,0,0,0,0,0,0,0,0,0,0];
y2 = [0.032258065,0.064516129,0,0,0.064516129,0.064516129,0.032258065,0.064516129,0.129032258,0.225806452,0.161290323,0.096774194,0.032258065,0.032258065,0,0,0,0,0,0,0,0,0,0,0];
y3 = [0,0,0,0.025641026,0.025641026,0.051282051,0.128205128,0,0,0.051282051,0,0.076923077,0.307692308,0.128205128,0,0.025641026,0,0.051282051,0.025641026,0,0.051282051,0.025641026,0.025641026,0,0];
x = categorical(n, n);
plot(x,y1,'-ko', x,y2,'-ks',x,y3,'-k^','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',7);
hold off

5 Kommentare

madhan ravi
madhan ravi am 9 Jul. 2020
What do you mean by 0-20? By the way format your code by pressing the code button so that it’s easy to read.
Elnaz P
Elnaz P am 9 Jul. 2020
Ok I did, just I want to shift Y axis from left on point 0-20, but two soultions (Ytick Label and Scale Up data), don't work yet.
madhan ravi
madhan ravi am 9 Jul. 2020
It would be better if you illustrate how it should look like using paint or something.
Elnaz P
Elnaz P am 9 Jul. 2020
Ok, I hope this will be more clear
Sugar Daddy
Sugar Daddy am 10 Jul. 2020
something like this

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Sugar Daddy
Sugar Daddy am 9 Jul. 2020
Bearbeitet: Sugar Daddy am 9 Jul. 2020

1 Stimme

Scale Up data

hold on
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
origin = (0-20);
n= ["-240-260";"-220-240";"-200-220";"-180-200";"-160-180";"-140-160";"-120-140";"-100-120";"-80-100";"-60-80";"-40-60";"-20-40";"0-20";"0+20";"+20+40";"+40+60";"+60+80";"+80+100";"+100+120";"+120+140";"+140+160";"+160+180";"+180+200";"+200+220";"+220+240"];
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.032258064516129,0.548387096774194,0.387096774193548,0.032258064516129,0,0,0,0,0,0,0,0,0,0];
y2 = [0.032258065,0.064516129,0,0,0.064516129,0.064516129,0.032258065,0.064516129,0.129032258,0.225806452,0.161290323,0.096774194,0.032258065,0.032258065,0,0,0,0,0,0,0,0,0,0,0];
y3 = [0,0,0,0.025641026,0.025641026,0.051282051,0.128205128,0,0,0.051282051,0,0.076923077,0.307692308,0.128205128,0,0.025641026,0,0.051282051,0.025641026,0,0.051282051,0.025641026,0.025641026,0,0];
x = categorical(n, n);
mv = max(max([y1;y2;y3]));
y1 = y1/mv*20;
y2 = y2/mv*20;
y3 = y3/mv*20;
plot(x,y1,'-ko', x,y2,'-ks',x,y3,'-k^','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',7);

Change Ytick Label

hold on
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
origin = (0-20);
n= ["-240-260";"-220-240";"-200-220";"-180-200";"-160-180";"-140-160";"-120-140";"-100-120";"-80-100";"-60-80";"-40-60";"-20-40";"0-20";"0+20";"+20+40";"+40+60";"+60+80";"+80+100";"+100+120";"+120+140";"+140+160";"+160+180";"+180+200";"+200+220";"+220+240"];
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.032258064516129,0.548387096774194,0.387096774193548,0.032258064516129,0,0,0,0,0,0,0,0,0,0];
y2 = [0.032258065,0.064516129,0,0,0.064516129,0.064516129,0.032258065,0.064516129,0.129032258,0.225806452,0.161290323,0.096774194,0.032258065,0.032258065,0,0,0,0,0,0,0,0,0,0,0];
y3 = [0,0,0,0.025641026,0.025641026,0.051282051,0.128205128,0,0,0.051282051,0,0.076923077,0.307692308,0.128205128,0,0.025641026,0,0.051282051,0.025641026,0,0.051282051,0.025641026,0.025641026,0,0];
x = categorical(n, n);
mv = max(max([y1;y2;y3]));
plot(x,y1,'-ko', x,y2,'-ks',x,y3,'-k^','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',7);
ax.YTickLabel= string(linspace(0,20,length(ax.YTickLabel)));

2 Kommentare

madhan ravi
madhan ravi am 9 Jul. 2020
Bearbeitet: madhan ravi am 9 Jul. 2020
+1, Ah ok now it’s clear 👌
Elnaz P
Elnaz P am 9 Jul. 2020
Bearbeitet: Elnaz P am 9 Jul. 2020
Yes I gonna shift Y axis from left on point 0-20, but by change Ytick Label it doesn't work yet

Melden Sie sich an, um zu kommentieren.

Steven Lord
Steven Lord am 9 Jul. 2020

0 Stimmen

I don't believe the axis ruler that is used when you plot using categorical data supports moving the axis location. In the situation you described we humans can see a reasonable definition for what 'origin' should probably mean (the bin whose label includes 0) but MATLAB can't see that (why is the bin whose name starts with the character '0' special?) In addition, if I were to try to place the axis at the 'origin' for the following plot where should the axis be placed and why should it be placed there?
c = ["cat", "broccoli", "sapphire"];
x = categorical(c, c);
h = plot(x, [4 7 1]);
ax = ancestor(h, 'axes');
ax.YAxisLocation = "origin";

2 Kommentare

Elnaz P
Elnaz P am 9 Jul. 2020
If I had ability to move the axis, it was more easy to analyze the data, in this plot data between 0 to -20 is origin. After zero, positive starts and before that negative. However thanks for your replay
You can't move the axis, but you could put a dividing line.
n= ["-240-260";"-220-240";"-200-220";"-180-200";"-160-180";"-140-160";"-120-140"; ...
"-100-120";"-80-100";"-60-80";"-40-60";"-20- 40";"0-20";"0+20";"+20+40";...
"+40+60";"+60+80";"+80+100";"+100+120";"+120+140";"+140+160";"+160+180";...
"+180+200";"+200+220";"+220+240"];
y1 = [0,0,0,0,0,0,0,0,0,0,0,0.04,0.32,0.56,0.08,0,0,0,0,0,0,0,0,0,0];
y2 = [0,0.05,0.05,0.05,0,0.1,0,0,0.2,0.3,0.1,0.1,0.05,0,0,0,0,0,0,0,0,0,0,0,0];
x=categorical(n, n);
plot(x,y1,'r--o', x,y2,'k--o');
% Category 13 in x is "0-20"
xline(x(13))

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 9 Jul. 2020

Kommentiert:

am 10 Jul. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by