Skip to content

Commit

Permalink
heatmap up
Browse files Browse the repository at this point in the history
  • Loading branch information
icweaver committed Feb 20, 2025
1 parent 4f98d99 commit d3ef658
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
28 changes: 16 additions & 12 deletions docs/src/plotting.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ model = CCM89()

```@example a
# Automatic limits defined by model
lines(model) # Or plot(model)
lines(model; linewidth=3, color=:cornflowerblue) # Or plot(model; [plot options])
```

```@example a
Expand Down Expand Up @@ -81,27 +81,31 @@ fig
```

## Dust map example
ImageLike plots like [`heatmap`](https://docs.makie.org/stable/reference/plots/heatmap#heatmap) and [`image`](https://docs.makie.org/stable/reference/plots/heatmap#heatmap) also work automatically:
A [`heatmap`](https://docs.makie.org/stable/reference/plots/heatmap#heatmap) plot also works automatically for [`DustExtinction.SFD98Map`](@ref):

```@example a
dustmap = SFD98Map()
l = range(-3, 3; length=400)
b = range(-1, 1; length=300)
m = [dustmap(li, bj) for li in l, bj in b]
heatmap(dustmap; colorrange=(0, 3), colormap=:cividis) # Or plot(dustmap; [plot kwargs])
```

Similarly to the extinction law plots, we can create our own custom dust map plots:

```@example a
using Unitful
lrange = range(-1, 1; length=400)u"°"
brange = range(-0.25, 0.25; length=300)u"°"
fig, ax, p = heatmap(l, b, m; colorrange=(0, 3), colormap=:cividis)
fig, ax, p = heatmap(lrange, brange, dustmap; colorrange=(0, 3), colormap=:cividis)
ax.xlabel = "l (°)"
ax.ylabel = "b (°)"
ax.xlabel = "l [°]"
ax.ylabel = "b [°]"
Colorbar(fig[1, 2], p; label="E(B - V)")
Colorbar(fig[1, 2], p; label="E(B - V) [mag]")
fig
```

!!! todo
Add `ImageLike` recipe

!!! tip
See [plotting.jl](https://github.com/JuliaAstro/DustExtinction.jl/blob/docs-makie/docs/src/plotting.jl) for more plotting examples. The convenience functions defined there are used to generate the other figures shown in this documentation.
30 changes: 22 additions & 8 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
module MakieExt
using DustExtinction
import DustExtinction: bounds, aa_to_invum, ExtinctionLaw
import Makie
import Makie as M

# Ex: plot(CCM89())
function Makie.convert_arguments(P::Makie.PointBased, law::ExtinctionLaw)
function M.convert_arguments(P::M.PointBased, law::ExtinctionLaw)
aa = range(bounds(law)...; length=1_000)
m = map(law, aa)
invum = map(aa_to_invum, aa)
return Makie.convert_arguments(P, invum, m)
return M.convert_arguments(P, invum, m)
end
Makie.plottype(::ExtinctionLaw) = Makie.Lines
M.plottype(::ExtinctionLaw) = M.Lines

# Ex: plot(wavs, CCM89())
function Makie.convert_arguments(P::Makie.PointBased, x, law::ExtinctionLaw)
function M.convert_arguments(P::M.PointBased, x, law::ExtinctionLaw)
m = map(law, x)
Makie.convert_arguments(P, x, m)
M.convert_arguments(P, x, m)
end
Makie.plottype(x, ::ExtinctionLaw) = Makie.Lines
M.plottype(x, ::ExtinctionLaw) = M.Lines

# TODO: Add `ImageLike` recipe
# Ex: heatmap(SFD98Map())
function M.convert_arguments(P::M.CellGrid, dustmap::SFD98Map)
l = range(-3, 3; length=400)
b = range(-1, 1; length=300)
m = [dustmap(li, bj) for li in l, bj in b]
return M.convert_arguments(P, l, b, m)

Check warning on line 27 in ext/MakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/MakieExt.jl#L23-L27

Added lines #L23 - L27 were not covered by tests
end
M.plottype(::SFD98Map) = M.Heatmap

Check warning on line 29 in ext/MakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/MakieExt.jl#L29

Added line #L29 was not covered by tests

# Ex: heatmap(lrange, brange, SFD98Map())
function M.convert_arguments(P::M.CellGrid, lrange, brange, dustmap::SFD98Map)
m = [dustmap(li, bj) for li in lrange, bj in brange]
return M.convert_arguments(P, lrange, brange, m)

Check warning on line 34 in ext/MakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/MakieExt.jl#L32-L34

Added lines #L32 - L34 were not covered by tests
end
M.plottype(x, y, ::SFD98Map) = M.Heatmap

Check warning on line 36 in ext/MakieExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/MakieExt.jl#L36

Added line #L36 was not covered by tests
end

0 comments on commit d3ef658

Please sign in to comment.