使用 Octave 绘制垂直线的最佳方法是什么?
19670 次
3 回答
5
所以,我有两种方法。一个是我找到的,另一个是我编的。
方法一:从这里。
%% Set x value where verticle line should intersect the x-axis.
x = 0;
%% plot a line between two points using plot([x1,x2],[y1,y2])
plot([x,x],[-10,10]);
方法2:略有不同的方法,完全相同的结果
%% Setup a vector of x values
x = linspace(0,0,100);
%% Setup a vector of y values
y = linspace(0,10,100);
%% Plot the paired points in a line
plot(x,y);
我认为方法 2 可能会在绘图过程之前将更多信息写入内存,并且它会更长,所以在我看来,方法 1 应该是更好的选择。如果您更喜欢方法 2,请确保您的 x 和 y 向量具有相同的维度,否则您最终会得到一堆点,而您的直线应该是。
于 2014-09-07T03:03:22.680 回答
4
不幸的是,在没有工作示例的情况下,用于做显而易见的事情的Octave文档可能非常糟糕。在绘图上画一条简单的线就是其中之一。
如前所述,以八度音阶绘制 直线非常愚蠢。这是对内存和处理的浪费。而是使用该line()
功能,在您的情节之上绘制。
line()函数需要 2 个非标准x 值和y 值向量,而不是point和 point的标准点斜率参数,通常由和表示。相反,您需要将其写为:和. 从而迷惑了每一个活着的灵魂!A
B
(x1,y1)
(x2,y2)
X=(x1,x2)
Y=(y1,y2)
以下是使用Octave语言执行此操作的正确方法示例:
pkg load statistics % Need to load the statistics package
x = randn (1,1000); % Normal Distribution of random numbers
clf; histfit(x) % Make a histogram plot of x and fit the data
ylim ([-20,100]) % Change the plot limits (to lift graph up)
% Draw the (vertical) line between (0,-10) and (0,90)
line ("xdata",[0,0], "ydata",[-10,90], "linewidth", 3)
结果:
于 2019-03-23T14:48:17.507 回答