Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sashansamarajeewa
Copy link

@sashansamarajeewa sashansamarajeewa commented Dec 31, 2024

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.

  1. Explain what is an inset plot.
  2. How to make an inset plot with an example.
  3. Explain key elements and related information.

Output image

image

Type of change

Delete options that do not apply:

  • Improving the Documentation

Checklist

  • Added or changed relevant sections in the documentation

@sashansamarajeewa sashansamarajeewa marked this pull request as ready for review December 31, 2024 10:25
@sashansamarajeewa
Copy link
Author

@ffreyer @jkrumbiegel It would be great if someone can review this PR and provide feedback :)

Comment on lines +16 to +18
using Pkg
Pkg.add("CairoMakie")
Pkg.add("MakieExtra")
Copy link
Collaborator

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.

Copy link
Member

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.

Comment on lines +67 to +74
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
```
Copy link
Collaborator

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?)

Comment on lines +99 to +100
zoom_lines!(ax_main, ax_inset)
save("output.png", fig) # hide
Copy link
Collaborator

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.
Copy link
Collaborator

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)

@jkrumbiegel
Copy link
Member

jkrumbiegel commented Jan 7, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Work in progress
Development

Successfully merging this pull request may close these issues.

[Docs FR] Add inset example
4 participants