Change Y-Axis position to desired origin?

17 ビュー (過去 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 Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by