Skip to content

docs: Plotting with Makie.jl #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
84a6d8a
basic impl started
icweaver Mar 9, 2025
e6dc26a
Merge branch 'SymbolicML:main' into makie
icweaver Mar 22, 2025
2eb116f
cleanup + started adding tests
icweaver Mar 29, 2025
bbf9eff
cleanup
icweaver Mar 29, 2025
5b7920f
fixed conversion bug
icweaver Mar 29, 2025
3362969
ax.dim1/2_conversion working!
icweaver Mar 29, 2025
e439270
started docs and tests
icweaver Mar 29, 2025
e68d3b0
Merge branch 'main' into makie
icweaver Mar 29, 2025
e1637d3
switched to 2-arg ustrip
icweaver Mar 29, 2025
8dcc31e
more tests
icweaver Mar 30, 2025
331d8c6
docs up
icweaver Mar 30, 2025
6492347
added docstring for DQConversion
icweaver Mar 30, 2025
b307dd8
enabled units_in_label option
icweaver Mar 30, 2025
43f95ab
reftest
icweaver Mar 30, 2025
90c5d46
up
icweaver Mar 30, 2025
7d83d1b
workaround for broadcasting error with s
icweaver Mar 30, 2025
66f8899
added reference to AoG
icweaver Mar 30, 2025
8336dc5
oop, put make.jl back
icweaver Mar 31, 2025
1c5127e
fr this time
icweaver Mar 31, 2025
2893c01
whitespace
icweaver Mar 31, 2025
d412ed6
Update ext/DynamicQuantitiesMakieExt.jl
icweaver May 13, 2025
1277f6f
relax Makie compat, lower bound set to unitful axis PR
icweaver May 13, 2025
1afe364
Update test/Project.toml
icweaver May 13, 2025
2d09a66
space out DQConversion docstring a bit
icweaver May 13, 2025
ef2d0d8
enforce SymbolicDimensions for DQConversion
icweaver May 13, 2025
ba44320
align with upstream, make Dates dep explicit
icweaver May 19, 2025
bbf2ea6
Merge branch 'main' into makie
icweaver May 27, 2025
cbd923f
Merge branch 'main' into makie
icweaver Jun 24, 2025
2b40a36
start upgrading to Makie v0.24
icweaver Jun 26, 2025
2f7086e
finished Makie v0.24 upgrade
icweaver Jun 27, 2025
3902fc1
roll back Makie extension, update docs
icweaver Jul 12, 2025
a717ccf
cleanup
icweaver Jul 12, 2025
0c39e0b
add compat entry for CairoMakie
icweaver Jul 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
# TODO: update when https://github.com/MakieOrg/Makie.jl/pull/5137 merged
CairoMakie = "0.15.3"
36 changes: 21 additions & 15 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,72 +40,78 @@ Also, using `DynamicQuantities.Constants`, we were able to obtain the (dimension
Let's solve a simple projectile motion problem.
First load the `DynamicQuantities` module:

```julia
```@example projectile
using DynamicQuantities
```

Set up initial conditions as quantities:

```julia
```@example projectile
# Can explicitly import units:
using DynamicQuantities: km, m, s, min

y0 = 10km
v0 = 250m/s
θ = deg2rad(60)
g = 9.81m/s^2
nothing # hide
Comment on lines 53 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
y0 = 10km
v0 = 250m/s
θ = deg2rad(60)
g = 9.81m/s^2
nothing # hide
y0 = 10km
v0 = 250m/s
θ = deg2rad(60)
g = 9.81m/s^2;

A bit simpler. Can you also use ; rather than nothing elsewhere too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, no dice just yet:

image

I noticed you mention this in your discussion with Abhro in #175, and I've wanted to try it out ever since. Is there something else that I could try? Found some relevant discussion here: JuliaDocs/Documenter.jl#1509

```

Next, we use trig functions to calculate x and y components of initial velocity.
`vx0` is the x component and
`vy0` is the y component:

```julia
```@example projectile
vx0 = v0 * cos(θ)
vy0 = v0 * sin(θ)
nothing # hide
```

Next, let's create a time vector from 0 seconds to 1.3 minutes.
Note that these are the same dimension (time), so it's fine to treat
them as dimensionally equivalent!

```julia
```@example projectile
t = range(0s, 1.3min, length=100)
nothing # hide
```

Next, use kinematic equations to calculate x and y as a function of time.
`x(t)` is the x position at time t, and
`y(t)` is the y position:

```julia
```@example projectile
x(t) = vx0*t
y(t) = vy0*t - 0.5*g*t^2 + y0
nothing # hide
```

These are functions, so let's evaluate them:

```julia
```@example projectile
x_si = x.(t)
y_si = y.(t)
nothing # hide
```

These are regular vectors of quantities
with `Dimensions` for physical dimensions.

Next, let's plot the trajectory.
First convert to km and strip units:
Next, let's plot the trajectory. We will use [Makie.jl](https://docs.makie.org/) for its nice unit support:

```julia
x_km = ustrip.(x_si .|> us"km")
y_km = ustrip.(y_si .|> us"km")
```
```@example projectile
using CairoMakie

Now, we plot:
# Convert to kilometers first
x_km = x_si .|> us"km"
y_km = y_si .|> us"km"

```julia
plot(x_km, y_km, label="Trajectory", xlabel="x [km]", ylabel="y [km]")
# Display
lines(x_km, y_km; label="Trajectory", axis=(xlabel="x [km]", ylabel="y [km]"))
```

See [Makie.jl > Dimension conversions](https://docs.makie.org/stable/explanations/dim-converts#Dimension-conversions) for more.

## 3. Using dimensional angles

Say that we wish to track angles as a unit, rather than assume
Expand Down