|
1 | 1 | # coding: utf-8 |
2 | 2 | module UnicodePlot |
3 | | - |
4 | | - |
5 | | -# ==Description |
6 | | -# |
7 | | -# Draws a staircase plot on a new canvas. |
8 | | -# |
9 | | -# The first vector `x` should contain the horizontal |
10 | | -# positions for all the points. The second vector `y` should then |
11 | | -# contain the corresponding vertical positions respectively. This |
12 | | -# means that the two vectors must be of the same length and |
13 | | -# ordering. |
14 | | -# |
15 | | -# ==Usage |
16 | | -# |
17 | | -# UnicodePlot.stairs(x, y, style: :post, name: "", title: "", xlabel: "", ylabel: "", labels: true, border: :solid, margin: 3, padding: 1, color: :auto, width: 40, height: 15, xlim: [0, 0], ylim: [0, 0], canvas: :braille, grid: true) |
18 | | -# |
19 | | -# @param x [Array<Numeric>] The horizontal position for each point. |
20 | | -# @param y [Array<Numeric>] The vertical position for each point. |
21 | | -# @param style [Symbol] Specifies where the transition of the stair takes place. Can be either `:pre` or `:post`. |
22 | | -# @param name [String] Annotation of the current drawing to be displayed on the right. |
23 | | -# @param height [Integer] Number of character rows that should be used for plotting. |
24 | | -# @param xlim [Array<Numeric>] Plotting range for the x axis. `[0, 0]` stands for automatic. |
25 | | -# @param ylim [Array<Numeric>] Plotting range for the y axis. `[0, 0]` stands for automatic. |
26 | | -# @param canvas [Symbol] The type of canvas that should be used for drawing. |
27 | | -# @param grid [Boolean] If `true`, draws grid-lines at the origin. |
28 | | -# |
29 | | -# @return [Plot] A plot object |
30 | | -# |
31 | | -# @example |
32 | | -# UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :post, title: "My Staircase Plot") |
33 | | -# |
34 | | -# |
35 | | -# ┌────────────────────────────────────────┐ |
36 | | -# 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
37 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
38 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
39 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
40 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
41 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
42 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
43 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│ |
44 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
45 | | -# │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
46 | | -# │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
47 | | -# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
48 | | -# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│ |
49 | | -# │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ |
50 | | -# 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ |
51 | | -# └────────────────────────────────────────┘ |
52 | | -# 1 8 |
53 | | -# |
54 | | -# @see Plot |
55 | | -# @see scatterplot |
56 | | -# @see lineplot |
57 | | -# |
| 3 | + # == Description |
| 4 | + # |
| 5 | + # Draws a staircase plot on a new canvas. |
| 6 | + # |
| 7 | + # The first vector `x` should contain the horizontal |
| 8 | + # positions for all the points. The second vector `y` should then |
| 9 | + # contain the corresponding vertical positions respectively. This |
| 10 | + # means that the two vectors must be of the same length and |
| 11 | + # ordering. |
| 12 | + # |
| 13 | + # == Usage |
| 14 | + # |
| 15 | + # UnicodePlot.stairs(x, y, style: :post, name: "", title: "", xlabel: "", ylabel: "", labels: true, border: :solid, margin: 3, padding: 1, color: :auto, width: 40, height: 15, xlim: [0, 0], ylim: [0, 0], canvas: :braille, grid: true) |
| 16 | + # |
| 17 | + # @param x [Array<Numeric>] The horizontal position for each point. |
| 18 | + # @param y [Array<Numeric>] The vertical position for each point. |
| 19 | + # @param style [Symbol] Specifies where the transition of the stair takes place. Can be either `:pre` or `:post`. |
| 20 | + # @param name [String] Annotation of the current drawing to be displayed on the right. |
| 21 | + # @param height [Integer] Number of character rows that should be used for plotting. |
| 22 | + # @param xlim [Array<Numeric>] Plotting range for the x axis. `[0, 0]` stands for automatic. |
| 23 | + # @param ylim [Array<Numeric>] Plotting range for the y axis. `[0, 0]` stands for automatic. |
| 24 | + # @param canvas [Symbol] The type of canvas that should be used for drawing. |
| 25 | + # @param grid [Boolean] If `true`, draws grid-lines at the origin. |
| 26 | + # |
| 27 | + # @return [Plot] A plot object |
| 28 | + # |
| 29 | + # @example |
| 30 | + # UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :post, title: "My Staircase Plot") |
| 31 | + # |
| 32 | + # |
| 33 | + # ┌────────────────────────────────────────┐ |
| 34 | + # 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 35 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 36 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 37 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 38 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 39 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 40 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ |
| 41 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│ |
| 42 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
| 43 | + # │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
| 44 | + # │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
| 45 | + # │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ |
| 46 | + # │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│ |
| 47 | + # │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ |
| 48 | + # 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ |
| 49 | + # └────────────────────────────────────────┘ |
| 50 | + # 1 8 |
| 51 | + # |
| 52 | + # @see Plot |
| 53 | + # @see scatterplot |
| 54 | + # @see lineplot |
| 55 | + # |
58 | 56 | module_function def stairs(xvec, yvec, style: :post, **kw) |
59 | 57 | x_vex, y_vex = compute_stair_lines(xvec, yvec, style: style) |
60 | 58 | lineplot(x_vex, y_vex, **kw) |
@@ -91,5 +89,4 @@ module UnicodePlot |
91 | 89 | end |
92 | 90 | return [x_vex, y_vex] |
93 | 91 | end |
94 | | - |
95 | 92 | end |
0 commit comments