4293ec98创建于 2022年12月11日历史提交

Line Plot 3d

Draw 3D line plots with given values of :math:x, :math:y and :math:z. One can also specify axes of the plot.

Examples

  1. Draw 3d line plot of a helix.

::

let t = linspace<Float64>(0.0, 10.0 * PI64, num: 500)
let st = t.apply(sin)
let ct = t.apply(cos)
plot3(st, ct, t)

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_1.png :align: center :width: 360

  1. Draw 3d line plot of two helixes with different colors.

::

let t = linspace<Float64>(0.0, PI64, num: 500)
let xt1 = t.apply({x: Float64 => sin(x) * cos(10.0 * x)})
let yt1 = t.apply({x: Float64 => sin(x) * sin(10.0 * x)})
let zt1 = t.apply(cos)
plot3(xt1, yt1, zt1)
hold(true)
let xt2 = t.apply({x: Float64 => sin(x) * cos(12.0 * x)})
let yt2 = t.apply({x: Float64 => sin(x) * sin(12.0 * x)})
let zt2 = t.apply(cos)
plot3(xt2, yt2, zt2)

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_2.png :align: center :width: 360

  1. Draw 3d line plot with three helixes.

::

let t = linspace<Float64>(0.0, PI64, num: 500)

let X = empty<Float64>(3, 500)
X[0] = t.apply({x: Float64 => sin(x) * cos(10.0 * x)})
X[1] = t.apply({x: Float64 => sin(x) * cos(12.0 * x)})
X[2] = t.apply({x: Float64 => sin(x) * cos(20.0 * x)})

let Y = empty<Float64>(3, 500)
Y[0] = t.apply({x: Float64 => sin(x) * sin(10.0 * x)})
Y[1] = t.apply({x: Float64 => sin(x) * sin(12.0 * x)})
Y[2] = t.apply({x: Float64 => sin(x) * sin(20.0 * x)})

let z = t.apply(cos)

plot3(X[0], Y[0], z)
hold(true)
plot3(X[1], Y[1], z)
plot3(X[2], Y[2], z)

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_3.png :align: center :width: 360

  1. Draw 3d line plot on a torus (note: original example has animation).

::

let t = linspace<Float64>(0.0, 40.0 * PI64, num: 20000)
let xt = t.apply({x: Float64 => (3.0 + cos(sqrt(32.0) * x)) * cos(x)})
let yt = t.apply({x: Float64 => sin(sqrt(32.0) * x)})
let zt = t.apply({x: Float64 => (3.0 + cos(sqrt(32.0) * x)) * sin(x)})
plot3(xt, yt, zt)
axis(AxisStyle.Equal)
xlabel("x(t)")
ylabel("y(t)")
zlabel("z(t)")

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_4.png :align: center :width: 360

  1. 3D line plot with custom markers.

::

let t = linspace<Float64>(0.0, 10.0 * PI64, num: 200)
let xt = t.apply(sin)
let yt = t.apply(cos)
plot3(xt, yt, t, line_spec: "-ob").marker_size(10.0).marker_face_color("#D9FFFF")
xlabel("x(t)")
ylabel("y(t)")
zlabel("t")

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_5.png :align: center :width: 360

  1. 3D line plot with custom line styles.

::

let t = linspace<Float64>(0.0, 10.0 * PI64, num: 200)
let xt1 = t.apply(sin)
let yt1 = t.apply(cos)
let xt2 = t.apply({t => sin(2.0 * t)})
let yt2 = t.apply({t => cos(2.0 * t)})
plot3(xt1, yt1, t, line_spec: "--")
hold(true)
plot3(xt2, yt2, t, line_spec: "--")

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_6.png :align: center :width: 360

  1. 3D line plot with custom line width.

::

let t = linspace<Float64>(-10.0, 10.0, num: 1000)
let xt = t.apply({x: Float64 => exp(-x / 10.0) * sin(5.0 * x)})
let yt = t.apply({x: Float64 => exp(-x / 10.0) * cos(5.0 * x)})
plot3(xt, yt, t).line_width(3.0)

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_7.png :align: center :width: 360

  1. 3D line plot on a tiled layout.

::

tiledlayout(1, 2)
let ax1 = nexttile()

let t1 = linspace<Float64>(0.0, 10.0 * PI64, num: 200)
let xt1 = t1.apply(sin)
let yt1 = t1.apply(cos)
plot3(ax1, xt1, yt1, t1)
title(ax1, "Helix with 5 Turns")

let ax2 = nexttile();
let t2 = linspace<Float64>(0.0, 10.0 * PI64, num: 200)
let xt2 = t2.apply({x: Float64 => sin(2.0 * x)})
let yt2 = t2.apply({x: Float64 => cos(2.0 * x)})
plot3(ax2, xt2, yt2, t2);
ax2.box(false);
title(ax2, "Helix with 10 Turns");

Result:

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_8.png :align: center :width: 360

::

let xt = linspace<Float64>(0.0, 10.0, num: 10)
let yt = xt
let zt = xt
plot3(xt, yt, zt, line_spec: "o")

xlabel("X")
ylabel("Y")
zlabel("Duration")
grid(true)

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_9.png :align: center :width: 360

  1. 3D line plot with a single marker.

::

let t = linspace<Float64>(0.0, PI64, num: 500)
let xt = t.apply({x: Float64 => sin(x) * cos(10.0 * x)})
let yt = t.apply({x: Float64 => sin(x) * sin(10.0 * x)})
let zt = t.apply(cos)
let p = plot3(xt, yt, zt, line_spec: "-o")
p.marker_indices(vector<Int64>([200]))

.. image:: ../../../tests/imgs/line_plot_3d/plot3d_10.png :align: center :width: 360

Methods

================== =================================== Method Description ================== =================================== plot3 2 methods Plot a 3d line with x, y, z. ================== ===================================

Description

.. function:: plot3(x, y, z, line_spec!)

:param x: Vector<Float64>
:param y: Vector<Float64>
:param z: Vector<Float64>
:param line_spec: String

Plot a 3d line with x, y, z.

.. function:: plot3(axes, x, y, z, line_spec!)

:param axes: AxesType
:param x: Vector<Float64>
:param y: Vector<Float64>
:param z: Vector<Float64>
:param line_spec: String

Plot a 3d line with x, y, z on the given axes.