Stairs
The stairs plot uses a horizontal line to represent each value. Input can be either vectors or matrices. In the case of matrices, an array of Stair handles may be returned.
Examples
- Plotting stairs for a single function, ignoring the :math:
x-component.
::
let x = linspace(0.0, 4.0 * PI64, num: 40);
let y = x.apply(sin)
figure();
stairs(y);
Result:
.. image:: ../../../tests/imgs/stairs/stairs_1.png :align: center :width: 360
- Plotting stairs for two functions, ignoring the :math:
x-component.
::
let x = linspace(0.0, 4.0 * PI64, num: 40)
let Y = zeros<Float64>(2, 40)
Y[0] = x.apply({x => 0.5 * cos(x)})
Y[1] = x.apply({x => 2.0 * cos(x)})
figure()
stairs(Y)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_2.png :align: center :width: 360
- Plotting stairs for a single function.
::
let x = linspace(0.0, 4.0 * PI64, num: 40)
let y = x.apply(sin)
figure()
stairs(x, y)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_3.png :align: center :width: 360
- Plotting stairs for two functions.
::
let x = linspace(0.0, 4.0 * PI64, num: 50)
let Y = zeros<Float64>(2, 50)
Y[0] = x.apply({x => 0.5 * cos(x)})
Y[1] = x.apply({x => 2.0 * cos(x)})
figure()
stairs(x, Y)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_4.png :align: center :width: 360
- Plotting two functions, each with different :math:
x-components.
::
let X = zeros<Float64>(2, 100)
X[0] = linspace(0.0, 2.0 * PI64)
X[1] = linspace(0.0, PI64)
let Y = zeros<Float64>(2, 100)
Y[0] = X[0].apply({x => sin(5.0 * x)})
Y[1] = X[1].apply({x => exp(x) * sin(5.0 * x)})
figure()
stairs(X, Y)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_5.png :align: center :width: 360
- Plotting stairs with custom line style (dashed line, red circles).
::
let x = linspace(0.0, 4.0 * PI64, num: 20)
let y = x.apply(sin)
figure()
stairs(x, y, line_spec: "-.or")
Result:
.. image:: ../../../tests/imgs/stairs/stairs_6.png :align: center :width: 360
- Customize the line width, marker, and marker face color of a stairs plot.
::
let x = linspace(0.0, 4.0 * PI64, num: 20)
let y = x.apply(sin)
stairs(x, y).line_width(2.0).marker("d").marker_face_color("c")
Result:
.. image:: ../../../tests/imgs/stairs/stairs_7.png :align: center :width: 360
- Plot stairs in different tiles.
::
let x = linspace(0.0, 2.0 * PI64)
let y1 = x.apply({ x => 5.0 * sin(x) })
let y2 = x.apply({ x => sin(5.0 * x) })
tiledlayout(2, 1)
let ax1 = nexttile()
stairs(ax1, x, y1)
let ax2 = nexttile()
stairs(ax2, x, y2)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_8.png :align: center :width: 360
- Use the returned line handles to customize style for each stair plot.
::
let x = linspace(0.0, 1.0, num:30)
let Y = zeros<Float64>(2, 30);
Y[0] = x.apply({ x => cos(10.0 * x) })
Y[1] = x.apply({ x => exp(x) * sin(10.0 * x) })
let h: Array<Stair> = stairs(x, Y)
h[0].marker(MarkerStyle.Circle).marker_size(4.0)
h[1].marker(MarkerStyle.Circle).marker_face_color("m")
Result:
.. image:: ../../../tests/imgs/stairs/stairs_9.png :align: center :width: 360
- Test for different stair styles.
::
let x = vector([1.0, 3.0, 5.0, 7.0, 10.0])
let y = vector([2.0, 5.0, 6.0, 7.0, 11.0])
let h1: Stair = stairs(x, y)
let h2: Stair = stairs(x, y)
let h3: Stair = stairs(x, y)
let h4: Stair = stairs(x, y)
h1.stair_style(StairStyle.Fill)
h2.stair_style(StairStyle.TraceXFirst).line_width(4.0)
h3.stair_style(StairStyle.TraceYFirst).line_width(2.0)
h4.stair_style(StairStyle.TraceHistogram).marker(MarkerStyle.Circle)
.line_width(1.0).marker_color("m").marker_face(true)
.marker_size(10.0)
Result:
.. image:: ../../../tests/imgs/stairs/stairs_10.png :align: center :width: 360
Methods
====================== ==================================== Method Description ====================== ==================================== stairs 6 methods Plot a stair line with y versus x ====================== ====================================
Description
.. function:: stairs(y, line_spec!)
:param y: Vector<Float64>
:param line_spec: String
:return: Stair
Plot a stair line with :math:`y`.
.. function:: stairs(x, y, line_spec!)
:param x: Vector<Float64>
:param y: Vector<Float64>
:param line_spec: String
:return: Stair
Plot a stair line with :math:`y` versus :math:`x`.
.. function:: stairs(x, y, line_spec!)
:param x: Vector<Float64>
:param y: Matrix<Float64>
:param line_spec: String
:return: Array<Stair>
Plot stair lines with :math:`y` versus :math:`x`. Each returned
handle corresponds to one row in :math:`y`.
.. function:: stairs(x, y, line_spec!)
:param x: Matrix<Float64>
:param y: Matrix<Float64>
:param line_spec: String
:return: Array<Stair>
Plot stair lines with :math:`y` versus :math:`x`. The two inputs should
have the same number of rows. Each returned handle corresponds to
one row in :math:`x` and :math:`y`.
.. function:: stairs(y, line_spec!)
:param y: Matrix<Float64>
:param line_spec: String
:return: Array<Stair>
Plot stair lines with :math:`y`. Each returned handle corresponds to
one row in :math:`y`.
.. function:: stairs(axes, x, y, line_spec!)
:param axes: AxesType
:param x: Vector<Float64>
:param y: Vector<Float64>
:param line_spec: String
:return: Stair
Plot stair on the given axes.