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

Error Bars

Plot error bars given the center value, and size of error on the :math:y-axis (optionally on the :math:x-axis as well).

Parameter errorbar_type is one of Vertical, Horizontal, and Both.

Examples

  1. Plotting error bars in the usual style.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector<Float64>(y.getSize(), { x => 10.0 })
errorbar(x, y, err)
axis(0.0, 100.0, 0.0, 110.0)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_1.png :align: center :width: 360

  1. Plotting error bars in the filled-curve style.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector<Float64>(y.getSize(), { x => 10.0 })
errorbar(x, y, err).filled_curve(true)
axis(0.0, 100.0, 0.0, 110.0)
save("./tests/imgs/errorbar/errorbar_2.png", "svg")

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_2.png :align: center :width: 360

  1. Plotting error bars with different error sizes.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector([5.0, 8.0, 2.0, 9.0, 3.0, 3.0, 8.0, 3.0, 9.0, 3.0])
errorbar(x, y, err)
axis(0.0, 100.0, 0.0, 110.0)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_3.png :align: center :width: 360

  1. Plotting error bars in the horizontal style.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector([1.0, 3.0, 5.0, 3.0, 5.0, 3.0, 6.0, 4.0, 3.0, 3.0])
errorbar(x, y, err, errorbar_type:ErrorBarType.Horizontal)
axis(0.0, 100.0, 0.0, 110.0)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_4.png :align: center :width: 360

  1. Plotting error bars with both horizontal and vertical errors. Note we set axis to Equal in order to align horizontal and vertical lengths.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector([4.0, 3.0, 5.0, 3.0, 5.0, 3.0, 6.0, 4.0, 3.0, 3.0])
errorbar(x, y, err, errorbar_type:ErrorBarType.Both)
axis(0.0, 100.0, 0.0, 110.0)
axis(AxisStyle.Equal)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_5.png :align: center :width: 360

  1. Plotting error bars with both horizontal and vertical errors, as well as custom line style (circle).

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let err = vector([4.0, 3.0, 5.0, 3.0, 5.0, 3.0, 6.0, 4.0, 3.0, 3.0])
errorbar(x, y, err, errorbar_type:ErrorBarType.Both, line_spec:"o")
axis(0.0, 100.0, 0.0, 100.0)
axis(AxisStyle.Equal)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_6.png :align: center :width: 360

  1. Plotting error bars with different errors in :math:x and :math:y-components, and with different upper and lower errors.

::

let x = arange<Float64>(0.0, 100.0, 10.0)
let y = vector([20.0, 30.0, 45.0, 40.0, 60.0, 65.0, 80.0, 75.0, 95.0, 90.0])
let yneg = vector([1.0, 3.0, 5.0, 3.0, 5.0, 3.0, 6.0, 4.0, 3.0, 3.0])
let ypos = vector([2.0, 5.0, 3.0, 5.0, 2.0, 5.0, 2.0, 2.0, 5.0, 5.0])
let xneg = vector([1.0, 3.0, 5.0, 3.0, 5.0, 3.0, 6.0, 4.0, 3.0, 3.0])
let xpos = vector([2.0, 5.0, 3.0, 5.0, 2.0, 5.0, 2.0, 2.0, 5.0, 5.0])
errorbar(x, y, yneg, ypos, xneg, xpos, line_spec:"o")
axis(0.0, 100.0, 0.0, 100.0)

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_7.png :align: center :width: 360

  1. Customize the marker size, marker color, and marker face color of error bars.

::

let x = linspace<Float64>(0.0, 10.0, num:15)
let y = x.apply({ x => sin(x / 2.0) })
let err = vector<Float64>(y.getSize(), { x => 0.3 })
var e:ErrorBar = errorbar(x, y, err, line_spec:"-s").marker_size(10.0)
                    .marker_color("red")
                    .marker_face_color("red")

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_8.png :align: center :width: 360

  1. Customize the cap-size of error bars.

::

let x = linspace<Float64>(0.0, 2.0, num:15)
let y = x.apply({ x => exp(x) })
let err = vector<Float64>(y.getSize(), { x => 0.3 })
var e:ErrorBar = errorbar(x, y, err).cap_size(18.0);

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_9.png :align: center :width: 360

  1. Customize the cap-size as well as other styles for error bars.

::

let x = linspace<Float64>(0.0, 10.0, num:10)
let y = x.apply({ x => sin(x / 2.0) })
let err = vector<Float64>(y.getSize(), { x => 0.3 })
var e:ErrorBar = errorbar(x, y, err).cap_size(15.0).marker("*")
                    .marker_size(10.0).color("red")

Result:

.. image:: ../../../tests/imgs/errorbar/errorbar_10.png :align: center :width: 360

Methods

====================== ==================================== Method Description ====================== ==================================== errorbar 2 methods Plot error bars ====================== ====================================

Description

.. function:: errorbar(x, y, error, errorbar_type!, line_spec!)

:param x: Vector<Float64>
:param y: Vector<Float64>
:param error: Vector<Float64>
:param errorbar_type: ErrorBarType
:param line_spec: String
:return: ErrorBar

Plot error bar with errors of the same size in each direction.

.. function:: errorbar(x, y, yneg, ypos, xneg, xpos, line_spec!)

:param x: Vector<Float64>
:param y: Vector<Float64>
:param yneg: Vector<Float64>
:param ypos: Vector<Float64>
:param xneg: Vector<Float64>
:param xpos: Vector<Float64>
:param line_spec: String
:return: ErrorBar

Plot error bar with different sizes of error in each direction.