如何在 Julia 中使用 plot() 连接点
How to connect points using plot() in Julia
我想在笛卡尔坐标系上连接点,如下图所示:
x = 1:10;
y = rand(10);
plot(x, y)
上图中这些点是随机的,x轴只能取1到10之间的值。
我想创建一个类似的图,我可以在其中分配特定点的位置(让我们命名这些点:[x_i, y_i])并连接它们。以下是 [x_i、y_i]
的一些值示例
[0,2], [4,-10], [5, 12], [12, 6]
来自docs:
you can plot a line by calling plot on two vectors of numbers.
您可以将 x_i
的矢量作为第一个参数传递给 plot
,将 y_i
的矢量作为第二个参数。然后 plot
会画一条线。例如:
plot([0, 4, 5, 12], [2, -10, 12, 6])
如果你必须将输入作为成对的[x_i, y_i]
,你可以在绘图之前做一些预处理。例如
input = [[0,2], [4,-10], [5,12], [12,6]]
4-element Vector{Vector{Int64}}:
[0, 2]
[4, -10]
[5, 12]
[12, 6]
plot([x for (x, y) in input], [y for (x, y) in input])
两者都产生输出:
我想在笛卡尔坐标系上连接点,如下图所示:
x = 1:10;
y = rand(10);
plot(x, y)
上图中这些点是随机的,x轴只能取1到10之间的值。
我想创建一个类似的图,我可以在其中分配特定点的位置(让我们命名这些点:[x_i, y_i])并连接它们。以下是 [x_i、y_i]
[0,2], [4,-10], [5, 12], [12, 6]
来自docs:
you can plot a line by calling plot on two vectors of numbers.
您可以将 x_i
的矢量作为第一个参数传递给 plot
,将 y_i
的矢量作为第二个参数。然后 plot
会画一条线。例如:
plot([0, 4, 5, 12], [2, -10, 12, 6])
如果你必须将输入作为成对的[x_i, y_i]
,你可以在绘图之前做一些预处理。例如
input = [[0,2], [4,-10], [5,12], [12,6]]
4-element Vector{Vector{Int64}}:
[0, 2]
[4, -10]
[5, 12]
[12, 6]
plot([x for (x, y) in input], [y for (x, y) in input])
两者都产生输出: