Skip to content

Commit

Permalink
re-generate README.md (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 26, 2023
1 parent a4744f3 commit e09475b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 33 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ Here is a list of the main high-level functions for common scenarios:
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot3.png" width="450"><br>

These mutating methods cannot update the limits of the axes (xlims & ylims) as plots are drawn onto a fixed canvas. The limits must be set by the plotting function that creates the figure or by creating an empty `Plot`:

These mutating methods cannot update the limits of the axes as plots are drawn onto a fixed canvas. The limits must be set beforehand by the plotting function that creates the figure or by creating an empty `Plot`:

```julia
p = Plot(; xlim=(-1, 3), ylim=(-1, 3))
lineplot!(p, 1:2)
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot4.png" width="450"><br>


One can adjust the plot `height` and `width` to the current terminal size by using `height=:auto` and/or `width=:auto`.

You can reverse/flip the `Plot` axes by setting `xflip=true` and/or `yflip=true` on plot creation.
Expand All @@ -78,31 +83,31 @@ Here is a list of the main high-level functions for common scenarios:
```julia
lineplot([1, 2, 7], [9, -6, 8], title="My Lineplot")
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot4.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot5.png" width="450"><br>


It's also possible to specify a function and a range:

```julia
plt = lineplot(-π/2, 2π, [cos, sin])
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot5.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot6.png" width="450"><br>


You can also plot lines by specifying an intercept and slope:

```julia
lineplot!(plt, -.5, .2, name="line")
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot6.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot7.png" width="450"><br>


Plotting multiple series is supported by providing a `Matrix` (`<: AbstractMatrix`) for the `y` argument, with the individual series corresponding to its columns. Auto-labeling is by default, but you can also label each series by providing a `Vector` or a `1xn` `Matrix` such as `["series 1" "series2" ...]`:

```julia
lineplot(1:10, [0:9 3:12 reverse(5:14) fill(4, 10)], color=[:green :red :yellow :cyan])
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot7.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot8.png" width="450"><br>


Physical quantities of [`Unitful.jl`](https://github.com/PainterQubits/Unitful.jl) are supported through [package extensions - weak dependencies](https://pkgdocs.julialang.org/dev/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)):
Expand All @@ -112,7 +117,7 @@ Here is a list of the main high-level functions for common scenarios:
a, t = 1u"m/s^2", (0:100) * u"s"
lineplot(a / 2 * t .^ 2, a * t, xlabel="position", ylabel="speed", height=10)
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot8.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot9.png" width="450"><br>


Intervals from [`IntervalSets.jl`](https://github.com/JuliaMath/IntervalSets.jl) are supported:
Expand All @@ -121,15 +126,15 @@ Here is a list of the main high-level functions for common scenarios:
using IntervalSets
lineplot(-1..3, x -> x^5 - 5x^4 + 5x^3 + 5x^2 - 6x - 1; name="quintic")
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot9.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot10.png" width="450"><br>


Use `head_tail` to mimic plotting arrows (`:head`, `:tail` or `:both`) where the length of the "arrow" head or tail is controlled using `head_tail_frac` where e.g. giving a value of `0.1` means `10%` of the segment length:

```julia
lineplot(1:10, 1:10, head_tail=:head, head_tail_frac=.1, height=4)
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot10.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot11.png" width="450"><br>


`UnicodePlots` exports `hline!` and `vline!` for drawing vertical and horizontal lines on a plot:
Expand All @@ -141,7 +146,7 @@ Here is a list of the main high-level functions for common scenarios:
hline!(p, 7, color=:cyan)
vline!(p, 1, color=:yellow)
```
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot11.png" width="450"><br>
<img src="https://github.com/JuliaPlots/UnicodePlots.jl/raw/unicodeplots-docs/3.x/lineplot12.png" width="450"><br>


</details>
Expand Down Expand Up @@ -623,7 +628,7 @@ The method `label!` is responsible for the setting all the textual decorations o
- `thousands_separator::Char = ' '`: thousands separator character (use `Char(0)` to disable grouping digits).
- `projection::Symbol = :orthographic`: projection for 3D plots (`:ortho(graphic)`, `:persp(ective)`, or `Model-View-Projection` (MVP) matrix).
- `axes3d::Bool = true`: draw 3d axes (`x -> :red`, `y -> :green`, `z -> :blue`).
- `elevation::Float = 35.26`: elevation angle above or below the `floor` plane (`-90 ≤ θ ≤ 90`).
- `elevation::Float = 35.264389682754654`: elevation angle above or below the `floor` plane (`-90 ≤ θ ≤ 90`).
- `azimuth::Float = 45.0`: azimutal angle around the `up` vector (`-180° ≤ φ ≤ 180°`).
- `zoom::Float = 1.0`: zooming factor in 3D.
- `up::Symbol = :z`: up vector (`:x`, `:y` or `:z`), prefix with `m -> -` or `p -> +` to change the sign e.g. `:mz` for `-z` axis pointing upwards.
Expand Down
55 changes: 32 additions & 23 deletions docs/gen_docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,38 @@ main() = begin
xlabel="x", ylabel="y", canvas=DotCanvas, border=:ascii)
"""),
lineplot3 = ("Basic Canvas", "lineplot!(plt, [0, 4, 8], [10, 1, 10], color=:cyan, name=\"other line\")"),
scatterplot1 = ("Scatterplot", "scatterplot(randn(50), randn(50), title=\"My Scatterplot\")"),
scatterplot2 = ("Scatterplot", "scatterplot(1:10, 1:10, xscale=:log10, yscale=:log10)"),
scatterplot3 = ("Scatterplot", "scatterplot(1:4, 1:4, xscale=:log10, yscale=:ln, unicode_exponent=false, height=6)"),
scatterplot4 = ("Scatterplot", """
scatterplot([1, 2, 3], [3, 4, 1], marker=[:circle, '', "∫"],
color=[:cyan, nothing, :yellow], height=2)
lineplot4 = ("Basic Canvas", """
p = Plot(; xlim=(-1, 3), ylim=(-1, 3))
lineplot!(p, 1:2)
"""),
lineplot4 = ("Lineplot", "lineplot([1, 2, 7], [9, -6, 8], title=\"My Lineplot\")"),
lineplot5 = ("Lineplot", "plt = lineplot(-π/2, 2π, [cos, sin])"),
lineplot6 = ("Lineplot", "lineplot!(plt, -.5, .2, name=\"line\")"),
lineplot7 = ("Lineplot", "lineplot(1:10, [0:9 3:12 reverse(5:14) fill(4, 10)], color=[:green :red :yellow :cyan])"),
lineplot8 = ("Lineplot", """
lineplot5 = ("Lineplot", "lineplot([1, 2, 7], [9, -6, 8], title=\"My Lineplot\")"),
lineplot6 = ("Lineplot", "plt = lineplot(-π/2, 2π, [cos, sin])"),
lineplot7 = ("Lineplot", "lineplot!(plt, -.5, .2, name=\"line\")"),
lineplot8 = ("Lineplot", "lineplot(1:10, [0:9 3:12 reverse(5:14) fill(4, 10)], color=[:green :red :yellow :cyan])"),
lineplot9 = ("Lineplot", """
using Unitful
a, t = 1u"m/s^2", (0:100) * u"s"
lineplot(a / 2 * t .^ 2, a * t, xlabel="position", ylabel="speed", height=10)
"""),
lineplot9 = ("Lineplot", """
lineplot10 = ("Lineplot", """
using IntervalSets
lineplot(-1..3, x -> x^5 - 5x^4 + 5x^3 + 5x^2 - 6x - 1; name="quintic")
"""),
lineplot10 = ("Lineplot", "lineplot(1:10, 1:10, head_tail=:head, head_tail_frac=.1, height=4)"),
lineplot11 = ("Lineplot", """
lineplot11 = ("Lineplot", "lineplot(1:10, 1:10, head_tail=:head, head_tail_frac=.1, height=4)"),
lineplot12 = ("Lineplot", """
p = Plot([NaN], [NaN]; xlim=(0, 8), ylim=(0, 8))
vline!(p, [2, 6], [2, 6], color=:red)
hline!(p, [2, 6], [2, 6], color=:white)
hline!(p, 7, color=:cyan)
vline!(p, 1, color=:yellow)
"""),
scatterplot1 = ("Scatterplot", "scatterplot(randn(50), randn(50), title=\"My Scatterplot\")"),
scatterplot2 = ("Scatterplot", "scatterplot(1:10, 1:10, xscale=:log10, yscale=:log10)"),
scatterplot3 = ("Scatterplot", "scatterplot(1:4, 1:4, xscale=:log10, yscale=:ln, unicode_exponent=false, height=6)"),
scatterplot4 = ("Scatterplot", """
scatterplot([1, 2, 3], [3, 4, 1], marker=[:circle, '', "∫"],
color=[:cyan, nothing, :yellow], height=2)
"""),
stairs1 = ("Staircase", """
stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7],
color=:yellow, style=:post, height=6, title="Staircase")
Expand Down Expand Up @@ -367,6 +371,10 @@ $(indent(examples.lineplot2))
$(indent(examples.lineplot3))
These mutating methods cannot update the limits of the axes as plots are drawn onto a fixed canvas. The limits must be set beforehand by the plotting function that creates the figure or by creating an empty `Plot`:
$(indent(examples.lineplot4))
One can adjust the plot `height` and `width` to the current terminal size by using `height=:auto` and/or `width=:auto`.
You can reverse/flip the `Plot` axes by setting `xflip=true` and/or `yflip=true` on plot creation.
Expand All @@ -376,35 +384,35 @@ $(indent(examples.lineplot3))
<details open>
$(summary("Lineplot"))
$(indent(examples.lineplot4))
$(indent(examples.lineplot5))
It's also possible to specify a function and a range:
$(indent(examples.lineplot5))
$(indent(examples.lineplot6))
You can also plot lines by specifying an intercept and slope:
$(indent(examples.lineplot6))
$(indent(examples.lineplot7))
Plotting multiple series is supported by providing a `Matrix` (`<: AbstractMatrix`) for the `y` argument, with the individual series corresponding to its columns. Auto-labeling is by default, but you can also label each series by providing a `Vector` or a `1xn` `Matrix` such as `["series 1" "series2" ...]`:
$(indent(examples.lineplot7))
$(indent(examples.lineplot8))
Physical quantities of [`Unitful.jl`](https://github.com/PainterQubits/Unitful.jl) are supported through [package extensions - weak dependencies](https://pkgdocs.julialang.org/dev/creating-packages/#Conditional-loading-of-code-in-packages-(Extensions)):
$(indent(examples.lineplot8))
$(indent(examples.lineplot9))
Intervals from [`IntervalSets.jl`](https://github.com/JuliaMath/IntervalSets.jl) are supported:
$(indent(examples.lineplot9))
$(indent(examples.lineplot10))
Use `head_tail` to mimic plotting arrows (`:head`, `:tail` or `:both`) where the length of the "arrow" head or tail is controlled using `head_tail_frac` where e.g. giving a value of `0.1` means `10%` of the segment length:
$(indent(examples.lineplot10))
$(indent(examples.lineplot11))
`UnicodePlots` exports `hline!` and `vline!` for drawing vertical and horizontal lines on a plot:
$(indent(examples.lineplot11))
$(indent(examples.lineplot12))
</details>
Expand Down Expand Up @@ -738,13 +746,14 @@ Inspired by [TextPlots.jl](https://github.com/sunetos/TextPlots.jl), which in tu
if true
cursor_hide(stdout)
run(`clear`)
print(stdout, g)
println(stdout, g)
win = if "WINDOWID" ∈ keys(ENV)
ENV["WINDOWID"]
else
readchomp(`xdotool getactivewindow`)
end
tmp = tempname()
sleep(1)
# XX%x100% => remove the right scrollbar (run in a big terminal window)
run(`import -window \$win -gravity West -crop 70%x100%+0+0 -trim -quality 100 \$tmp.miff`)
# FIXME: export to `jpg` format, since we have an issue with rendering this `png` on github
Expand Down

0 comments on commit e09475b

Please sign in to comment.