Change Y-Axis position to desired origin?

조회 수: 15 (최근 30일)
Elnaz P
Elnaz P 2020년 7월 9일
댓글: Steven Lord 2020년 7월 10일
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
Elnaz P
Elnaz P 2020년 7월 9일
Ok, I hope this will be more clear
Sugar Daddy
Sugar Daddy 2020년 7월 10일
something like this

댓글을 달려면 로그인하십시오.

답변 (2개)

Sugar Daddy
Sugar Daddy 2020년 7월 9일
편집: Sugar Daddy 2020년 7월 9일

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
madhan ravi
madhan ravi 2020년 7월 9일
편집: madhan ravi 2020년 7월 9일
+1, Ah ok now it’s clear 👌
Elnaz P
Elnaz P 2020년 7월 9일
편집: Elnaz P 2020년 7월 9일
Yes I gonna shift Y axis from left on point 0-20, but by change Ytick Label it doesn't work yet

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2020년 7월 9일
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
Elnaz P
Elnaz P 2020년 7월 9일
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
Steven Lord
Steven Lord 2020년 7월 10일
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))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by