如何让y轴位于x = 0?

时间:2017-05-20 04:58:40

标签: plot octave

我希望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都不能像指数刻度这样简单,它们甚至不能将零置于它所属的位置。

2 个答案:

答案 0 :(得分:1)

这已经添加了变更集http://hg.savannah.gnu.org/hgweb/octave/rev/1ddb53b6ad30,并且已经是GNU Octave 4.2.0版本的一部分。

由于您没有提及使用过的版本,或者如果您收到警告或错误消息,我可以猜测您使用的是旧版本

编辑:我不确定OpenGL对(x / y)轴位置的支持是否已经是4.2.0的一部分。我可以肯定地说它适用于当前的开发源,并且它适用于带有graphics_toolkit gnuplot

的4.2.0

答案 1 :(得分:1)

  

我希望x = 0在y轴上。

对我来说,你正在尝试的声音使得绘图从x轴上的0开始。 所以你要找的是一个设置x轴限制的功能。

xlim函数可以做到这一点,或者您可以更普遍地使用axis来同时设置x和y轴限制。请参阅the octave documentation page on this

E.g。使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线上,即使它位于图形的中间,而不是比如说,固定在图的左侧或右侧,然后按照该链接上的说明进行操作。基本上:

set(gca, 'yaxislocation', 'origin');

(注意:值'0'曾经是这个参数的有效值,但是这个值已被弃用,而不是“origin”这个值做同样的事情。)