-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
New recipe: lens #2372
New recipe: lens #2372
Conversation
@@ -801,6 +801,50 @@ end | |||
# note: don't add dependencies because this really isn't a drop-in replacement | |||
|
|||
|
|||
# --------------------------------------------------------------------------- | |||
# lens! - magnify a region of a plot | |||
@recipe function f(::Type{Val{:lens}}, plt::AbstractPlot) |
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'm surprised this works - it's the type recipe signature, which is usually just used for type conversions to vector. Should this not be a "user recipe" with a @userplot
shorthand defined?
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 thought, this is the signature of a plot recipe ( and a valid usecase )
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.
also I would like to only define the lens!
shorthand, since lens
by itself doesn't make too much sense.
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.
Ah you're right. I don't think they are used anywhere in the ecosystem, but I may be wrong (it lists MarginalHist as an example, but looking down on that page clearly shows that marginalhist is a "user recipe"). Defining a lens!
shorthand makes sense - but I feel that calling it with seriestype
as done here feels unideomatic.
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.
What would be a more ideomatic alternative? I don't bother too much to change this.
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.
Just the lens!
shorthand? Sorry I have zero experience using plot recipes
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.
Okay, now I got it. You meant the way to call the recipe is unideomatic, I thought the implementation with using the seriestype
. I will add the lens!
shorthand.
I thought, adding a ghost subplot for the connecting line would help, but, since the bounding box of the parent box seems to get calculated afterwards it still affects his axis limits. Also some backends have problems if the inset plot is outside of the parent plot. |
Easiest course of action would be to get rid of the connecting line altogether and just have the box + inset. |
This is the best I can do without having access to the bounding box of the parent plot. |
@BeastyBlacksmith are you waiting for me here? |
@mkborregaard Would be nice if you can confirm that I can't get the bounding box of the current plot at the recipe stage or if I am looking for the wrong thing and layout information is stored elsewhere. |
Whether the bounding box is present depends on the recipe type. With this being a type recipe, I'm pretty sure it isn't - if it were a series recipe it would be present as a key in a captured |
ce81c96
to
6f80c0e
Compare
Ok, that worked. Could use some testing before merge. pl = plot((1:5).^2)
lens!(pl, [1.2, 2.8], [3.4, 7.8], inset=(1,bbox(0.5,0.2,0.5,0.5))) |
You could add a testing image to |
I added the example and made sure, I can easily revert the formatting changes, if they don't belong here. |
src/examples.jl
Outdated
@@ -311,6 +311,21 @@ const _examples = PlotExample[ | |||
], | |||
), | |||
PlotExample( | |||
"Lens", | |||
"A lens lets you easyli magnify a region of a plot. x and y coordinates refer to the to be magnified region and the via the `inset` keyword the subplot index and the bounding box (in relative coordinates) of the inset plot with the magnified plot can be specified. Additional attributes count for the inset plot.", |
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.
typo
src/examples.jl
Outdated
end | ||
], | ||
), | ||
* PlotExample( |
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.
stray *
Nice - would you mind splitting the formatting changes to a separate PR? |
No, never did this. |
Firstly, I'd suggest putting new test_examples at the end of To update the PlotReferenceImages, you basically have to
After the PlotReferenceImages PR is merged, the tests of this PR will pass |
cd2b060
to
696ece1
Compare
fe265ca
to
3de69e3
Compare
3de69e3
to
ae065c9
Compare
The lens recipe should magnify a certain region and show it in an inset plot.
Current API is
Where you pass the magnifying region as
x
andy
values and the location of the inset as usually.Currently only relative bounding boxes are supported. Location of the linking line has to be improved.
Also drawing of the linking line should actually be outside of any plot, so it doesn't infer with axis limits of the parent plot, but I don't know if this is possible.
fixes #541