-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Add a tutorial on creating an inset plot #4697
base: master
Are you sure you want to change the base?
Add a tutorial on creating an inset plot #4697
Conversation
@ffreyer @jkrumbiegel It would be great if someone can review this PR and provide feedback :) |
using Pkg | ||
Pkg.add("CairoMakie") | ||
Pkg.add("MakieExtra") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pkg adds shouldn't be here. CairoMakie should be available and MakieExtra should be added to https://github.com/MakieOrg/Makie.jl/blob/master/docs/Project.toml instead. I think it's also reasonable to assume that people know how to add packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what is MakieExtra even added? On first sight it all looks like normal Makie code.
We need to define the data for the inset. For instance, zoom into a specific time range to show detailed price movement. | ||
|
||
```@figure inset | ||
time_inset = time[50:70] | ||
stock_price_inset = stock_price[50:70] | ||
line_inset = lines!(ax_inset, time_inset, stock_price_inset, color=:red) | ||
fig | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think setting x/ylims is preferable since creating a zoomed subset of your data might be difficult. (Unless that doesn't work?)
zoom_lines!(ax_main, ax_inset) | ||
save("output.png", fig) # hide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is more personal preference but I'd like this to be MakieExtras.zoom_lines!(...)
so you can easily see what functionality you need MakieExtras for. Maybe also move the using MakieExtras
here to further clarify.
I think the save
here is unnecessary and should be deleted
|
||
### 2. `translate!` Function and Z-Ordering | ||
|
||
**z-order** (depth) determines the rendering order of elements, with higher z-values appearing in front of lower ones. This is critical for ensuring that the inset plot is visible above the main plot. By explicitly setting the z-value via translate! function, you can layer elements as needed. If translate! is omitted or the z-value is too low, the inset plot may render behind the main plot, making it invisible or partially obscured. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to give a bit background information here. If you search for "translate" in https://github.com/MakieOrg/Makie.jl/blob/master/src/makielayout/blocks/axis.jl and https://github.com/MakieOrg/Makie.jl/blob/master/src/makielayout/lineaxis.jl you'll find translates between -100 (Axis background) and +20 (frame lines (?)) / +10 (tick lines) / +0 (tick text, titles). User plots are naturally at 0.
So you need at least +100 for the background of the inset to compete with (un-translated) user plots. Depending on when the plots are created you might need to be over 100.
If you would want the inset axis to draw partially outside the axis you'd need at least +120. (I'm not sure if layouting would let you do this though.) The maximum z you're allowed to have is 10_000.
The tutorial should simplify that information. Maybe just mention that Axis spans a z range of -100 to +20 and adjust the translate you used before to something like 150 to be safe. And also mention that if you z-translate plots in the big Axis you may need to shift the inset Axis more. (I.e. you want plot_translate < inset_axis_translate - 100
)
I think the part with the zoom lines would be better suited for the MakieExtras docs as it describes how to use its functions, and not how to do generic operations with Makies objects. I don't want to document other packages here if I don't have to as it increases the overall burden of keeping things up to date, plus, MakieExtras is specifically a package doing nonstandard things with some internals use etc. |
Description
Fixes #3292
This PR adds a tutorial on creating an inset plot. The related issue #3292 discusses 2 approaches to address this but I opted for the initial suggestion described in #3292 (comment).
The tutorial consists of 3 main parts.
Output image
Type of change
Delete options that do not apply:
Checklist