Skip to content

Add example of keys to explore 3D data #18221

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

Closed
tacaswell opened this issue Aug 11, 2020 · 3 comments
Closed

Add example of keys to explore 3D data #18221

tacaswell opened this issue Aug 11, 2020 · 3 comments
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: mplot3d
Milestone

Comments

@tacaswell
Copy link
Member

tacaswell commented Aug 11, 2020

This snippet of code from @fermrav:

    def move_view(event):
            ax.autoscale(enable=False, axis='both')  # I have no idea, it this line have some effect at all
            ## Set nearly similar speed of motion in dependency on zoom
            if view_2D:
                koef = 4.  ## Speed for 2D should be higher
            else:
                koef = 8.  ## speed for 3D should be lower
                zkoef = (ax.get_zbound()[0] - ax.get_zbound()[1]) / koef

            xkoef = (ax.get_xbound()[0] - ax.get_xbound()[1]) / koef
            ykoef = (ax.get_ybound()[0] - ax.get_ybound()[1]) / koef

            ## Map an motion to keyboard shortcuts
            if event.key == "ctrl+down":
                ax.set_ybound(ax.get_ybound()[0] + xkoef, ax.get_ybound()[1] + xkoef)
            if event.key == "ctrl+up":
                ax.set_ybound(ax.get_ybound()[0] - xkoef, ax.get_ybound()[1] - xkoef)
            if event.key == "ctrl+right":
                ax.set_xbound(ax.get_xbound()[0] + ykoef, ax.get_xbound()[1] + ykoef)
            if event.key == "ctrl+left":
                ax.set_xbound(ax.get_xbound()[0] - ykoef, ax.get_xbound()[1] - ykoef)
            if not view_2D:
                if event.key == "down":
                    ax.set_zbound(ax.get_zbound()[0] - zkoef, ax.get_zbound()[1] - zkoef)
                if event.key == "up":
                    ax.set_zbound(ax.get_zbound()[0] + zkoef, ax.get_zbound()[1] + zkoef)
            # print event.key

        fig.canvas.mpl_connect("key_press_event", move_view)

should be turned into an example in https://github.com/matplotlib/matplotlib/tree/master/examples/event_handling (including showing how to disable the default keybinding via rcparam

Originally posted by @fermrav in #110 (comment)

@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! topic: mplot3d Documentation labels Aug 11, 2020
@tacaswell tacaswell added this to the v3.4.0 milestone Aug 11, 2020
@fermrav
Copy link

fermrav commented Aug 12, 2020

This snippet of code from @fermrav:

    def move_view(event):
            ax.autoscale(enable=False, axis='both')  # I have no idea, it this line have some effect at all
            ## Set nearly similar speed of motion in dependency on zoom
            if view_2D:
                koef = 4.  ## Speed for 2D should be higher
            else:
                koef = 8.  ## speed for 3D should be lower
                zkoef = (ax.get_zbound()[0] - ax.get_zbound()[1]) / koef

            xkoef = (ax.get_xbound()[0] - ax.get_xbound()[1]) / koef
            ykoef = (ax.get_ybound()[0] - ax.get_ybound()[1]) / koef

            ## Map an motion to keyboard shortcuts
            if event.key == "ctrl+down":
                ax.set_ybound(ax.get_ybound()[0] + xkoef, ax.get_ybound()[1] + xkoef)
            if event.key == "ctrl+up":
                ax.set_ybound(ax.get_ybound()[0] - xkoef, ax.get_ybound()[1] - xkoef)
            if event.key == "ctrl+right":
                ax.set_xbound(ax.get_xbound()[0] + ykoef, ax.get_xbound()[1] + ykoef)
            if event.key == "ctrl+left":
                ax.set_xbound(ax.get_xbound()[0] - ykoef, ax.get_xbound()[1] - ykoef)
            if not view_2D:
                if event.key == "down":
                    ax.set_zbound(ax.get_zbound()[0] - zkoef, ax.get_zbound()[1] - zkoef)
                if event.key == "up":
                    ax.set_zbound(ax.get_zbound()[0] + zkoef, ax.get_zbound()[1] + zkoef)
            # print event.key

        fig.canvas.mpl_connect("key_press_event", move_view)

should be turned into an example in https://github.com/matplotlib/matplotlib/tree/master/examples/event_handling (including showing how to disable the default keybinding via rcparam

Originally posted by @fermrav in #110 (comment)

Feel free to do so, but as I ment at original comment, I have no idea, how to override default keybindings. On another hand I will appreciate, if you add default keybinding override :)

@kristian-cho
Copy link

Hey, is anyone working on this? I was thinking of doing it.

@timhoffm
Copy link
Member

timhoffm commented Nov 8, 2020

@kristian-cho thanks for your interest. I think this has been superseeded by #18536.

See also: #110 (comment)

@tacaswell please reopen if this is still useful.

@timhoffm timhoffm closed this as completed Nov 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Good first issue Open a pull request against these issues if there are no active ones! topic: mplot3d
Projects
None yet
Development

No branches or pull requests

4 participants