Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
CreateInsetIndicator
artist#27996
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Added a |
fce57eb
to3d725ea
ComparePerhaps instead of inheriting from |
story645 commentedJul 28, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
That sounds like a fairly common use case to me so I think that'd be awesome. Is there an advantage to the rectangle approach/downside to making it a container? |
Not that I can think of. I think I just had in mind from#23424 (comment) that the new object should be a |
story645 commentedJul 28, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Technicallyartist w/ face color + edgecolor & for the most part I've always thought of it as roughly the MPL abstraction of an area mark b/c that's basically the space of visual encodings we allow/can apply to most of our patch artists: Where size and shape are controlled by the drawing of the shape, while for example the choice of marker determines shape and marker size controls the size. So for what it's worth, I agree w/ your intuition that a container Artist is probably a better abstraction for what's actually going on here. |
rcomer commentedAug 11, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
OK, the One side-effect of this is that we no longer get the axes limits updated around the artist, which is done in matplotlib/lib/matplotlib/axes/_base.py Line 2414 in1e98377
I guess it would be pretty easy to re-instate that but I'm not sure if it matters. Most of the time there will be a bunch of other artists that this one isindicating. Still to do:
|
Added changenotes and directives, though I'm not sure if the behaviour change documentation for |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
I hid the alpha discussion because that was addressed by#28710 and is not needed for the reviewers of this PR. |
It is also used by When you said "container" I was worried you were following what we do with e.g. error bar where we return a |
why did the lower left and upper right segments disappear? |
yeah, that is all a bit tricky. The rectangle would ideally clip to the parent axes; probably easy. The connectors would ideally clip the parent axes as well, but only on the side that links to the rectangle. I'm not aware that we have a way to do that and I'm not sure it's worth the hassle to make it. Either you are doing this for data exploration, in which case a little mess is OK, or you are doing it for a final plot, in which case you can clean up the positions then. |
You mean the connectors? Only 2 of those are visible by default. |
Thanks! Sorry for not checking the docs 🤦♀️ |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
for conn in self.connectors or []: | ||
if conn.get_visible(): | ||
drawn = False | ||
for s in _shared_properties: |
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.
Isn't it also the case that if the non-shared properties differ, then you can't merge the paths? For example,zorder
isn't listed as shared, but might make a difference.
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.
Yeah, I wasn't super-happy about doing this with a hard-coded list, but so far haven't thought of a better way. Very happy to take suggestions/pointers.
... oh I just realised I could useArtistInspector.get_setters
to make a complete list - maybe that's part of the solution, though we'd have to actively skip comparing some properties liketransform 🤔
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 also just realised that I currently have thezorder going toRectangle
in the__init__
when it should be getting applied toInsetIndicator
. So I need a better way to keep the properties straight at that end too.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
6e106e9
to143a228
CompareUh oh!
There was an error while loading.Please reload this page.
inset_indicator.rectangle : `.Rectangle` | ||
The indicator frame. | ||
inset_indicator.connectors : 4-tuple of `.patches.ConnectionPatch` | ||
The four connector lines connecting to (lower_left, upper_left, | ||
lower_right upper_right) corners of *inset_ax*. Two lines are | ||
set with visibility to *False*, but the user can set the | ||
visibility to True if the automatic choice is not deemed correct. | ||
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.
would it make sense to make this an interpolated doc, even if it's only used in like two places? That way it can be defined in the module? Only thinking about this b/c of how it's being done for colorizer:
matplotlib/lib/matplotlib/colorizer.py
Lines 29 to 34 incf9a943
mpl._docstring.interpd.update( | |
colorizer_doc="""\ | |
colorizer : `~matplotlib.colorizer.Colorizer` or None, default: None | |
The Colorizer object used to map color to data. If None, a Colorizer | |
object is created base on *norm* and *cmap*.""", | |
) |
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.
Possibly can do something even more direct but I do not follow this example at allhttps://matplotlib.org/devdocs/devel/document.html#keyword-arguments
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.
Do we have any general guidance about when it makes sense to do this rather than copy/paste? As you say it's only in two places and I am keenly aware that I have a lot more copy/paste going on in the artist'sset_*
docstrings.
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.
Uh oh!
There was an error while loading.Please reload this page.
lib/matplotlib/tests/test_inset.py Outdated
if conn.get_visible(): | ||
# Make one visible connector a different style | ||
conn.set_linestyle('dashed') | ||
conn.set_color('blue') | ||
break |
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.
shouldn't you know which connector this is b/c this is deterministic? basically why loop?
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 was just too lazy to figure out which index it would be...
Uh oh!
There was an error while loading.Please reload this page.
Is this no longer PoC (as in title)? |
d2cd137
toadb8a95
Compareadb8a95
to4d944bb
Compare4d944bb
tob833055
CompareI just noticed I forgot to update the deprecation warning when the patch became an artist. Nowfixed. |
ea78e25
intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR summary
#19768 (comment) suggested that we should have some kind of container for the output of
indicate_inset[_zoom]
.#23424 (comment) suggested that it should be drawn as a single path to avoid double-alpha where the box and connectors overlap. This PR is my attempt to implement that.The new artist has convenience methods to update colour/linestyle/etc for the whole thing, but the user can also get hold of individual patches and update styles on those. The current doctrings of
indicate_inset[_zoom]
specifically mention updating the visibility of the connectors, but a user might also reasonably want a different colour or linestyle for the connectors than for the box.The logic from
indicate_inset_zoom
that decided where the box should be is now methodInsetIndicator._bounds_from_inset_ax
so we can reuse it. Whenever theconnectors
attribute is accessed (including at draw) the box bounds and position of connectors (if any) get updated using the current inset axes x- and y-limits. This thereforecloses#19768 and we can do things likeStyles for the connectors are now inherited from the parent artist when the connectors are created. This thereforecloses#23424. Within the
draw
method, we check which connectors have the same style properties as the rectangle (currently four specific properties - maybe there is a better way). Those that do are drawn with the rectangle as a compound path.This also inadvertentlyfixes#23425 since I haven't implemented
get_window_extent
orget_tight_bbox
, so constrained layout will get a null tight bbox. I would like advice on whether I should implement one or both of these and what it should include. For the purposes of layout engines is does not seem useful to include the connectors, but maybe there are other uses for these methods?PR checklist