Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Inset Zoom Axes with Automatic Plotting of Parent Axes Artists.#22060

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

Closed
isaacrobinson2000 wants to merge15 commits intomatplotlib:mainfromisaacrobinson2000:add_autoplot_inset_axes
Closed

Add Inset Zoom Axes with Automatic Plotting of Parent Axes Artists.#22060

isaacrobinson2000 wants to merge15 commits intomatplotlib:mainfromisaacrobinson2000:add_autoplot_inset_axes

Conversation

isaacrobinson2000
Copy link
Member

@isaacrobinson2000isaacrobinson2000 commentedDec 29, 2021
edited
Loading

PR Summary

Extends the inset axes API adding a new methodAxes.inset_zoom_axes. Has the same signature and behavior asinset_axes, except it returns a subclass ofAxes capable of automatically rendering the contents of the parent axes. This means plot elements don't need to be plotted again on the inset axes to be visible.

importmatplotlib.pyplotaspltimportnumpyasnpnp.random.seed(1)fig=plt.figure()ax=fig.gca()# A line, some text, and an image...ax.plot([iforiinrange(10)],"r")ax.text(3,2.5,"Hello World!",ha="center")ax.imshow(np.random.rand(30,30),origin="lower",cmap="Blues",alpha=0.5)# Setup the zoom axes, no additional plotting needed...axins=ax.inset_zoom_axes([0.5,0.5,0.48,0.48])axins.set_xlim(1,5)axins.set_ylim(1,5)ax.indicate_inset_zoom(axins,edgecolor="black")plt.show()

Resulting Plot with Inset Zoom View

Supports all artists types (some of them shown in the above example), and any new ones that may eventually be added. It achieves this using a customRenderer which transforms the data before deferring it the the actual underlyingRenderer which does the actual drawing. It should work on all backends, I've personally tested the svg, png, pdf, and qt backends. I initially implemented this for a personal project and thought it might be nice to have directly in matplotlib.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

story645 reacted with thumbs up emoji
Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@jklymak
Copy link
Member

This looks really cool, and I'm sure a number of folks would like this.

However, this would be a significant new maintenance burden, so there is a bit of a cost-benefit analysis to be done. Do we want a whole shadow canvas just for this feature? Are there other uses for this concept?

I'm also concerned about consistency. You increase the size of image pixels (OK), you increase the size of text (maybe OK), but you donot increase the thickness of lines. What happens to markers? Do they zoom or stay the same? It seems that if you want a zoom, then you want everything to zoom?

@isaacrobinson2000
Copy link
MemberAuthor

Thanks for the feedback, it's appreciated.

The maintenance concerns are totally understandable, and if it's determined this is too much to take on that is okay with me. I've tried to implement the_TransformRenderer andViewAxes so that they can be reused for other features where a view of another axes is needed (not just inset axes). The axes can be directly placed in the figure also, as shown below:

importmatplotlib.pyplotaspltfrommatplotlib.axes._zoom_axesimportViewAxesimportnumpyasnpnp.random.seed(1)fig=plt.figure()ax=fig.add_axes([0,0,0.5,1])ax.plot([iforiinrange(10)],"r-o")ax.text(3,2.5,"Hello World!",ha="center")ax.imshow(np.random.rand(30,30),origin="lower",cmap="Blues",alpha=0.5)defViewOf(ax):defviewgen(fig,*args,**kwargs):returnViewAxes(ax,*args,**kwargs)returnviewgenax2=fig.add_axes([0.5,0,0.5,1],axes_class=ViewOf(ax))ax2.set_aspect("equal")ax2.set_xlim(-15,45)ax2.set_ylim(-15,45)fig.show()

test5result
This auto-view feature is especially useful in interactive plots where you want the view to dynamically update when artists are added/removed, and is actually the primary reason I developed this feature.

Also, thanks for bringing up the visual inconsistencies when displaying zoomed in versions of lines, which were an oversight on my part. I've fixed it in the most recent push and everything should zoom in together now (as depicted in the figure below).
autoplot_inset_axes-1

jklymak and scottshambaugh reacted with thumbs up emoji

@timhoffm
Copy link
Member

I've not looked into the details here: Could this start off as a third-party package. That's a good way to make code public if we are not yet sure whether we can maintain it in the main library.

story645 reacted with thumbs up emoji

@isaacrobinson2000
Copy link
MemberAuthor

I hadn't considered starting this off as a third-party package, though I think thats a great idea, I'll start working on getting one together as soon as I have some free time to do so. Is there any preference in how the third party package should integrate itself into matplotlib (API wise)?

@anntzer
Copy link
Contributor

I think the approach here looks quite cool, but I also agree that this can reasonably start as a third-party package.

@tacaswell
Copy link
Member

We talked about this on the call today, this is super cool! The proposed path forward here is :

  • make this a stand-alone package on@isaacrobinson2000 's account and get it on pypi
  • once that is done, move it into the Matplotlib org (where we would obviously give@isaacrobinson2000 full control of the repo)
  • in a year or two once we are sure the API has stabilized, then move the code into the main repo

I would suggest anytime you want to write anAxes method to instead write a free-function with the first argument being anAxes e.g.

ax.foo(...)foo(ax, ...)

The biggest advantage of letting this start as a stand-alone project is that you will be able to do releases more-or-less at will rather than being tied to our ~6mo intended (7-8mo actual) release cycle, push to the repo at will, and have the ability to aggressively make breaking changes to the API.

A concern about doing this as a stand-alone project is you are touching a number of private methods on the renderer, however those have been stable for a very long time and if the end-goal is to get this in the main repo, we think that is a reasonable risk.

@isaacrobinson2000
Copy link
MemberAuthor

I'm happy to hear that you're still interested in incorporating this into matplotlib. I think the concept of starting it as a third party package makes a lot of sense, as after making this PR I've realized there are some additional features that might be desired (such as adding elements to the axes which is a view of another, which currently doesn't work) and the API can be made much cleaner than the one in this PR. I've gone ahead and gone through with the first step above as suggested, and set up a repo and PyPI package for this project. I've also reworked the code so it can be easily applied to any Axes.

Github Repo:

https://github.com/isaacrobinson2000/matplotview

PyPI Package:

https://pypi.org/project/matplotview/

Since this is now a third party package, I'm assuming this PR is not really necessary nor helpful at this point, meaning it can probably be closed. Again, thanks for all of the helpful feedback!

@tacaswell
Copy link
Member

Sounds good@isaacrobinson2000 !

Can you please add it tohttps://github.com/matplotlib/mpl-third-party as well (and make sure you add theFramework :: Matplotlib classifier)?

@isaacrobinson2000
Copy link
MemberAuthor

Thanks! I've made the above edits. Looking at the second step above, should I just go ahead and transfer the matplotview repo to the matplotlib organization, or is there something that should be done before I do that?

@tacaswell
Copy link
Member

@isaacrobinson2000 Add me as a collaborator with I think admin rights on your repo and I'll do the move.

@isaacrobinson2000
Copy link
MemberAuthor

Thanks, let me know if you can do the move, there doesn't seem to be any options for collaborator permissions in the settings.

@tacaswell
Copy link
Member

Hmm, they have changed their ACL from the last time I looked at doing this. Can you try transferring it to me?

@isaacrobinson2000
Copy link
MemberAuthor

Sure, consider it done!

@tacaswell
Copy link
Member

This now lives athttps://github.com/matplotlib/matplotview

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@isaacrobinson2000@jklymak@timhoffm@anntzer@tacaswell@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp