如何让y轴位于x=0?
How to make y axis lie on x=0?
我希望 x=0 在 y 轴上。现在它不起作用。我尝试执行此命令,但它不起作用
set(gca, "yaxislocation", "zero")
我的代码。
labels = [0 128 256 512 1024 2048]; % Provide your labels here
ylabels = [0 1 2 4 8 16 32]; % Provide your labels here
hold on;
% system1 durations in seconds
plot (3, 1 ,'o' ,"markersize", 12);
plot (4, 1, 'o' ,"markersize", 12);
plot (5, 30, 'o' ,"markersize", 12);
plot (6, 150, 'o' ,"markersize", 12);
% system2 durations in seconds
plot (3, 2 ,'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (4, 2, 'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (5, 10, 'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (6, 30, 'x' ,"markersize", 12, "markerfacecolor", "auto");
% system3 durations in seconds
plot (3, 2 ,'d' ,"markersize", 12, "markerfacecolor", "auto");
plot (4, 7, 'd' ,"markersize", 12, "markerfacecolor", "auto");
plot (5, 18, 'd' ,"markersize", 12, "markerfacecolor", "auto");
plot (6, 22, 'd' ,"markersize", 12, "markerfacecolor", "auto");
%set(gca, 'xtick', x); % Change the x-axis so only the right amount of ticks remain
%set(gca, 'xticklabel', labels) % Change the labels to the desired ones
%set(gca, 'yticklabel', ylabels) % Change the labels to the desired ones
%set(gca, "xaxislocation", "zero")
set(gca, "yaxislocation", "zero")
%axis([0,1, miny, maxy]); axis "autox";
我试图在 y 轴和 x 轴上显示指数刻度,但这是不可能的。我的结论是octave没用,gnuplot也不行,还是手工画图比较好。 matlab 和 octave 都不能做指数标度这样简单的东西,他们甚至不能把零放在它应该的地方。
这已添加到变更集 http://hg.savannah.gnu.org/hgweb/octave/rev/1ddb53b6ad30 并且已经是 GNU Octave 4.2.0 版本的一部分。
由于您没有提及使用过的版本,或者如果您收到警告或错误消息,我只能猜测您使用的是旧版本
编辑:我不太确定 OpenGL 对 (x/y)axislocation 的支持是否已经是 4.2.0 的一部分。我可以肯定地说它适用于当前的开发源,并且适用于 graphics_toolkit gnuplot
的 4.2.0
I want x=0 to be on the y axis.
对我来说,听起来像是你在尝试让情节从 x 轴上的 0 开始。
所以你要找的是一个设置 x 轴限制的函数。
xlim
function does just that, or you can use axis
more generally to set both the x and y axis limits at the same time. See the octave documentation page on this.
例如使 x 轴从 0 开始到 100:
xlim([0,100]);
请注意,yaxislocation
做了完全不同的事情。
参见 https://uk.mathworks.com/help/matlab/examples/controlling-axis-location.html?searchHighlight=yaxislocation&s_tid=doc_srchtitle
如果您要做的是让 y 轴及其标签始终出现在 x=0 线上,即使它位于图表的中间,而不是固定在图形的左侧或右侧,然后按照 link 上的说明进行操作。本质上:
set(gca, 'yaxislocation', 'origin');
(注意:值 'zero' 曾经是此参数的有效值,但已弃用,取而代之的是执行相同操作的值 'origin')。
我希望 x=0 在 y 轴上。现在它不起作用。我尝试执行此命令,但它不起作用
set(gca, "yaxislocation", "zero")
我的代码。
labels = [0 128 256 512 1024 2048]; % Provide your labels here
ylabels = [0 1 2 4 8 16 32]; % Provide your labels here
hold on;
% system1 durations in seconds
plot (3, 1 ,'o' ,"markersize", 12);
plot (4, 1, 'o' ,"markersize", 12);
plot (5, 30, 'o' ,"markersize", 12);
plot (6, 150, 'o' ,"markersize", 12);
% system2 durations in seconds
plot (3, 2 ,'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (4, 2, 'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (5, 10, 'x' ,"markersize", 12, "markerfacecolor", "auto");
plot (6, 30, 'x' ,"markersize", 12, "markerfacecolor", "auto");
% system3 durations in seconds
plot (3, 2 ,'d' ,"markersize", 12, "markerfacecolor", "auto");
plot (4, 7, 'd' ,"markersize", 12, "markerfacecolor", "auto");
plot (5, 18, 'd' ,"markersize", 12, "markerfacecolor", "auto");
plot (6, 22, 'd' ,"markersize", 12, "markerfacecolor", "auto");
%set(gca, 'xtick', x); % Change the x-axis so only the right amount of ticks remain
%set(gca, 'xticklabel', labels) % Change the labels to the desired ones
%set(gca, 'yticklabel', ylabels) % Change the labels to the desired ones
%set(gca, "xaxislocation", "zero")
set(gca, "yaxislocation", "zero")
%axis([0,1, miny, maxy]); axis "autox";
我试图在 y 轴和 x 轴上显示指数刻度,但这是不可能的。我的结论是octave没用,gnuplot也不行,还是手工画图比较好。 matlab 和 octave 都不能做指数标度这样简单的东西,他们甚至不能把零放在它应该的地方。
这已添加到变更集 http://hg.savannah.gnu.org/hgweb/octave/rev/1ddb53b6ad30 并且已经是 GNU Octave 4.2.0 版本的一部分。
由于您没有提及使用过的版本,或者如果您收到警告或错误消息,我只能猜测您使用的是旧版本
编辑:我不太确定 OpenGL 对 (x/y)axislocation 的支持是否已经是 4.2.0 的一部分。我可以肯定地说它适用于当前的开发源,并且适用于 graphics_toolkit gnuplot
I want x=0 to be on the y axis.
对我来说,听起来像是你在尝试让情节从 x 轴上的 0 开始。 所以你要找的是一个设置 x 轴限制的函数。
xlim
function does just that, or you can use axis
more generally to set both the x and y axis limits at the same time. See the octave documentation page on this.
例如使 x 轴从 0 开始到 100:
xlim([0,100]);
请注意,yaxislocation
做了完全不同的事情。
参见 https://uk.mathworks.com/help/matlab/examples/controlling-axis-location.html?searchHighlight=yaxislocation&s_tid=doc_srchtitle
如果您要做的是让 y 轴及其标签始终出现在 x=0 线上,即使它位于图表的中间,而不是固定在图形的左侧或右侧,然后按照 link 上的说明进行操作。本质上:
set(gca, 'yaxislocation', 'origin');
(注意:值 'zero' 曾经是此参数的有效值,但已弃用,取而代之的是执行相同操作的值 'origin')。