-
Notifications
You must be signed in to change notification settings - Fork 9
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
Plotting recipes (in order to clean up doc plots) #36
Comments
Hey all, I've started learning about plot recipes to try and have a go at this, but I think that I am running into a problem with the bounds. It seems that evaluating at the lower wavelength limit throws an error, while evaluating at the upper limit seems fine: > law = GCC09()
GCC09
Rv: Float64 3.1
> bound_lower, bound_upper = bounds(law)
(909.09, 3030.3)
> law(bound_lower)
ERROR: out of bounds of GCC09, support is over (909.09, 3030.3) angstrom
> law(bound_upper)
1.8451270235624522 Is it intended for the bounds to not be inclusive on the lower end? If so, should there be some sort of tolerance we should add to the plot recipe to avoid going out of bounds? For now, I've just been doing something like this as a toy example: @recipe function f(t::T) where T <: ExtinctionLaw
@inline aa_to_invum(wave::Real) = 10000 / wave
lower, upper = bounds(t)
w = range(lower + 0.1, upper, length=1000)
w_invum = aa_to_invum.(w)
w_invum, t.(w)
end |
No, the intention is that Why is this happening?It seems like there slight inconsistencies in the bounds and the if-else branch inside The lower bound is 909.09 Angstrom, which is what is the solution?Fix the inconsistency! Either we need to change the output of If we change the bounds, they should become
If we change the branching, it should become
How do we stop this in the future?This should be easy to wrap into a test that can be used for all the laws, I can open a PR for this briefly. Edit: oops, this for-loop already exists, it just doesn't test if the law doesn't error. The recipeWhat you've got looks pretty good! A couple notes
|
Awesome, thanks for the PR and the recipe tips! I'm looking forward to trying these out |
this looks like a great start! FYI for the multi-RV plots, you should be able to condense this begin
fig = plot()
Rvs = [2.0, 3.1, 4.0, 5.0, 6.0]
for Rv in Rvs
law = F04(Rv)
plot!(law)
end
fig
end to this! begin
Rvs = [2.0 3.1 4.0 5.0 6.0]
plot(F04.(Rvs))
end Some improvements: I'd put the number of points into a kwarg The pluto notebook looks pretty cool, I enjoy the html outputs |
Hi Ian from the past. Looking at this with fresh eyes, I'm inclined to follow DimensionalData.jl's lead of deprecating Plots.jl support in favor of Makie.jl and their recipes system. Do other folks have thoughts one way or the other on this? |
I'm a matplotlib guy and have minimal experience with Plots.jl and none with Makie so I'm not clear on what the benefits / drawbacks of the two systems are. If you're volunteering to update the plots in the docs I'm happy for you to choose. The only opinions I would offer are
|
bet. Sounds like you and Miles think a lot alike, haha. I added a quick notebook here to start noodling around with some potential designs. Here's a snippet of the current impl. I've got standing: function Makie.convert_arguments(P::PointBased, law::ExtinctionLaw)
aa = range(bounds(law)...; length=1_000)
m = map(law, aa)
invum = map(aa_to_invum, aa)
return convert_arguments(P, invum, m) # (Plot type, x, y)
end lplot(law::Union{CCM89, OD94, CAL00, GCC09, VCG04, FM90}; args...) = lines(
law;
axis = (;
xlabel = rich("x [μm", superscript("-1"), "]"),
ylabel = "E(B-V)",
),
args...,
)
<and friends for composing other plots together> Makie.jl primitives workingand composite plots tooComments welcome! Can hopefully start getting unit support and more customization going after an initial design is firmed up |
Looks like a good start! Is there a reason you are dispatching on long unions (e.g., I'm used to seeing reddening laws expressed as |
You read my mind. Yep, those unwieldy unions were just my clumsy way of trying to follow the current spec of the y-axis label units that we have Dust stuff is far outside of my field, so I did't want to assume, but I'm all for unifying things if that seems reasonable to you! |
Mkay, the rest of the plots should be up now. I settled on the following spellings:
Not super tied to these names, and it might even be better to handle this in the type system with a |
I think this looks right but it's not like I've gone through every model to check whether they are defined as This is personal preference but I would like to see the text labels a bit larger and fully black for better legibility -- they are a bit difficult to read for me ATM. Other than that I think they look good 👍 |
Sounds good Thanks for that feedback! Do you have a preference between one of the predefined themes here? We could also just roll our own. Personally, I like plots that don't try and mix different fonts together |
The default theme looks fine on that page -- did you use theme_light on your notebook? I find theme_light harder to read |
Sounds good. Yep, will switch it over to default. I'm also super rusty of doc stuff, so I will make sure to take some time to re-familiarize myself with best practices used here before opening a PR 👍🏾 |
I've only done it once but my workflow for building plots and including them in docs was
Moving the figures from where they were generated into the build folder is nice so it doesn't leave plot figures scattered in the source directory when you build the docs locally rather than CI. Also There might be an easier way to manage the file paths (i.e., the difference between where the plots are generated and where they are included) but I don't know what it is. I wonder if you can just do |
Alright, have a first crack at this up #58. It's a fairly substantial change, but hopefully for the better. Will continue discussion about it over there |
We have all of the information required to plot a dust law in the
ExtinctionLaw
structs, so we should be able to create a plotting recipe withRecipesBase
to enable usage likecreating this plot recipe should be pretty easy and very similar to the recipes used in Polynomials.jl.
In terms of the interface, I think we need three key components
Here's what I think would be easiest to accomplish that interface
bounds
of the law. Add a recipe with boundsf(::ExtinctionLaw, a, b)
and a recipe with an iterablef(::ExtincitonLaw, X)
unit="invum"
. Other string options includeunit="angstrom"
,unit="micron"
, etc. Really we should just use Unitful for parsing these, except for the"invum"
case since that won't show up in unitful despite being (AFAIK) a de facto unit.The onus for these recipes is to stop doing what we're doing with the plot docs, which is writing scripts that must be evaluated locally to generate plots that are checked out into version control and then only used for docs. A much better workflow would be to have the plots made as part of the documentation step, and ideally we can show the plotting code inside the docs for full reproducibility. After making these recipes, the docs should be able to be rewritten without the plots dir, and instead with simple
plot(law)
calls using Documenter's@example
blocks.The text was updated successfully, but these errors were encountered: