6fbec8f3创建于 2022年6月24日历史提交

Function Contour

Examples

  1. Use fcontour to plot the :math:sin(x)+cos(y) function.

::

let f = {x: Float64, y: Float64 => sin(x) + cos(y)}
fcontour(f)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_1.png :align: center :width: 360

  1. Plotting two function contours side-by-side in the same axis.

::

fcontour({x, y => erf(x) + cos(y)}, xmin:-5.0, xmax:0.0, ymin:-5.0, ymax:5.0,
         levels: linspace(-2.0, 2.0, num: 5))
hold(true)
fcontour({x, y => sin(x) + cos(y)}, xmin:0.0, xmax:5.0, ymin:-5.0, ymax:5.0,
         levels: linspace(-2.0, 2.0, num: 5))
hold(false)
axis(-5.0, 5.0, -5.0, 5.0)
grid(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_2.png :align: center :width: 360

  1. Plotting function contours with custom line spec and line width.

::

let f = {x: Float64, y: Float64 => pow(x, 2.0) - pow(y, 2.0)}
fcontour(f, line_spec:"--").line_width(2.0)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_3.png :align: center :width: 360

  1. Plot two function contours superimposed onto each other.

::

fcontour({x, y => sin(x) + cos(y)})
hold(true)
fcontour({x, y => x - y})
hold(false)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_4.png :align: center :width: 360

  1. Plot function contour with custom line width, line style and level sets.

::

let f = {x: Float64, y: Float64 =>
    exp(-pow(x / 3.0, 2.0) - pow(y / 3.0, 2.0)) +
    exp(-pow(x + 2.0, 2.0) - pow(y + 2.0, 2.0))
}
fcontour(f).line_width(1.0).line_style("--")
           .levels(vector([1.0, 0.9, 0.8, 0.2, 0.1]))

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_5.png :align: center :width: 360

  1. Plot filled function contour.

::

let f = {x: Float64, y: Float64 =>
    erf(pow(y + 2.0, 3.0)) -
    exp(-0.65 * (pow(x - 2.0, 2.0) + pow(y - 2.0, 2.0)))
}
fcontour(f).filled(true).colormap_line_when_filled(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_6.png :align: center :width: 360

  1. Plot filled function contour with a custom number of levels.

::

let f = {x: Float64, y: Float64 =>
    erf(pow(y + 2.0, 3.0)) -
    exp(-0.65 * (pow(x - 2.0, 2.0) + pow(y - 2.0, 2.0)))
}
fcontour(f, n_levels:25).filled(true).colormap_line_when_filled(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_7.png :align: center :width: 360

  1. Plot function :math:sin(x)+cos(y) with custom levels.

::

fcontour({x, y => sin(x) + cos(y)}).levels(vector([-1.0, 0.0, 1.0]))

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_8.png :align: center :width: 360

  1. Plot filled function contour of the Rastrigin function.

::

let rastrigin = {x: Float64, y: Float64 =>
    20.0 + pow(x, 2.0) - 10.0 * cos(2.0 * PI64 * x) + pow(y, 2.0) -
    10.0 * cos(2.0 * PI64 * y)
}
fcontour(rastrigin).filled(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_9.png :align: center :width: 360

  1. Plot filled function contour of the Ackley function.

::

let ackley = {x: Float64, y: Float64 =>
    -20.0 * exp(-0.2 * sqrt(0.5 * (pow(x, 2.0) + pow(y, 2.0)))) -
    exp(0.5 * (cos(2.0 * PI64 * x) + cos(2.0 * PI64 * y))) + exp(1.0) + 20.0
}
fcontour(ackley).n_levels(10).filled(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_10.png :align: center :width: 360

  1. Plot filled function contour of the Rosenbrock function.

::

let rosenbrock = {x: Float64, y: Float64 =>
    100.0 * pow(y - pow(x, 2.0), 2.0) + pow(1.0 - x, 2.0)
}
fcontour(rosenbrock).n_levels(10).filled(true)

Result:

.. image:: ../../../tests/imgs/fcontour/fcontour_11.png :align: center :width: 360