c19dc2da创建于 2022年9月16日历史提交

Function Plot

Plotting the graph of functions, either of a single function (:math:f(x) against :math:x), or two functions (:math:g(x) against :math:f(x)).

Examples

  1. Plotting two functions on the same graph.

::

fplot({t => cos(t)}, -10.0, 10.0, line_spec: "o-r").line_width(2.0)
hold(true)
fplot({t => sin(t)}, -10.0, 10.0, line_spec: "x--b").line_width(2.0)

Result:

.. image:: ../../../tests/imgs/func_plot/func_plot1.png :align: center :width: 360

  1. Plotting two functions against each other.

::

fplot({t => cos(3.0 * t)}, {t => sin(2.0 * t)}, -10.0, 10.0)

Result:

.. image:: ../../../tests/imgs/func_plot/func_plot2.png :align: center :width: 360

  1. Plotting two functions with different x-range.

::

fplot({t => exp(t)}, -3.0, 0.0, line_spec: "b")
hold(true)
fplot(cos, 0.0, 3.0, line_spec: "b")
hold(false)
grid(true)

Result:

.. image:: ../../../tests/imgs/func_plot/func_plot3.png :align: center :width: 360

  1. Plotting with different line style.

::

let line1 = fplot({x => sin(x + PI64 / 5.0)})
line1.line_width(2.0)
hold(true)
fplot({x => sin(x - PI64 / 5.0)}, line_spec: "--or")
fplot({x => sin(x)}, line_spec: "-.*c")

Result:

.. image:: ../../../tests/imgs/func_plot/func_plot4.png :align: center :width: 360

  1. Plotting with different line style, color, and marker.

::

let line = fplot({x => sin(x)})
line.line_style(":")
line.color("r")
line.marker("x")
line.marker_color("b")

Result:

.. image:: ../../../tests/imgs/func_plot/func_plot5.png :align: center :width: 360

  1. Plotting with user-defined ticks and tick labels.

::

fplot({x => sin(x)}, -2.0 * PI64, 2.0 * PI64)
grid(true)
title("sin(x) from -2π to 2π")
xlabel("x")
ylabel("y")
xticks(linspace(-2.0 * PI64, 2.0 * PI64, num: 9))
xticklabels(["-2π", "-3π/2", "-π", "-π/2", "0", "π/2", "π", "3π/2", "2π"])

.. image:: ../../../tests/imgs/func_plot/func_plot6.png :align: center :width: 360

Methods

====================== ========================================== Method Description ====================== ========================================== fplot 3 methods Plot given function f(x) ====================== ==========================================

Description

.. function:: fplot(f, start, end, line_spec!)

:param f: (Float64)->Float64
:param start: Float64
:param end: Float64
:param line_spec: String

Plot a line with given function f(x), with given range of y and mesh density.

.. function:: fplot(f, line_spec)

:param f: (Float64)->Float64
:param line_spec: String

Plot a line with given function f(x).

.. function:: fplot(fx, fy, start, end, mesh_density!, line_spec!)

:param fx: (Float64)->Float64
:param fx: (Float64)->Float64
:param fx: (Float64)->Float64
:param fx: (Float64)->Float64
:param fy: (Float64)->Float64
:param start: Float64
:param end: Float64
:param mesh_density: Int64
:param line_spec: String

Plot a line with given function; fx, fy are functions with variable t.

.. fimplicit::(f, startx!, endx!, starty!, endy!, mesh_density!, line_spec!) :param f: (Float64, Float64)->Float64 :param startx: Float64 :param endx: Float64 :param starty: Float64 :param endy: Float64 :param mesh_density: Int64 :param line_spec: String

Plot a line with given implicit funtion like f(x, y) = x + y.