Skip to content

Context Menu for snapping view to primary axis planes in 3D plots#6

Closed
AdwaithBatchu wants to merge 3 commits intor3kste:mainfrom
AdwaithBatchu:context-menu-3d
Closed

Context Menu for snapping view to primary axis planes in 3D plots#6
AdwaithBatchu wants to merge 3 commits intor3kste:mainfrom
AdwaithBatchu:context-menu-3d

Conversation

@AdwaithBatchu
Copy link
Collaborator

@AdwaithBatchu AdwaithBatchu commented Dec 24, 2025

PR summary

closes 23544
This PR introduces a feature that adds context menu on 3d Axes triggered by right-click of the mouse.

  1. Added context_menu() in Figure Manager that takes arguments, a list of labels and a list of corresponding functions to execute upon selection.

  2. Modified _button_release() to call canvas.manager.context_menu() with functions for setting orthographic views when the right-click is released on the mouse without moving it significantly. Mouse movement is handled in _on_move() using a small threshold because previously I observed trackpad (on macOS) reported micro-movements during a static click, which falsely flagged the action as "drag" and blocked the menu in specific backends.

Backends

  • TkAgg: tk.Menu implementation.
  • QtAgg: QtWidgets.QMenu implementation.
  • WxAgg: Uses wx.Menu and PopupMenu.
  • Gtk3Agg: Uses Gtk.Menu.
  • Gtk4Agg: Uses Gtk.PopoverMenu and Gio.Menu.
  • MacOSX: Uses AppKit (PyObjC) to display a native NSMenu, utilizing a target/action dispatcher.
  • WebAgg: Yet to be implemented
  • NbAgg: Yet to be implemented
import matplotlib

# matplotlib.use("TkAgg") # Change to QtAgg, GTK4Agg, MacOSX, WxAgg, etc.
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.plot([0, 1, 2], [0, 1, 0], [0, 1, 0])

plt.show()

PR checklist

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

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

@AdwaithBatchu The backend implementation is slightly wrong right now. As discussed previously:

  • There should be no mention of 3d axes or view_init within the backend files. After all these files should be as general as possible.
  • You only need to add a function named context_menu in the FigureManager class.

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

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

@AdwaithBatchu I have some concerns about implementation in Gtk4 and MacOSX.

Apart from that, I want you to link to the official documentation of the context_menu for each backend. For example, I have added a comment for qt backend. Do this for the other implemented backends.

@AdwaithBatchu AdwaithBatchu requested a review from r3kste January 2, 2026 12:15
Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

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

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

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

@AdwaithBatchu This is pretty close. The main thing is that

Make sure all backends use a consistent method for determining location
1. Current mouse position
2. Extract coords from event

Both will (should) give the exact same output, but for sake of consistency we should use a single method. I think (ii) is better, but let me know if you think otherwise

Copy link
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

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

@AdwaithBatchu AdwaithBatchu force-pushed the context-menu-3d branch 5 times, most recently from a2510b9 to d21caa3 Compare January 16, 2026 15:06
@r3kste r3kste changed the title Context menu 3d Context Menu for Axes3d to set orthographic views Jan 16, 2026
@r3kste r3kste changed the title Context Menu for Axes3d to set orthographic views Context Menu for snapping view to primary axis planes in 3D plots Jan 16, 2026
@r3kste r3kste closed this Jan 28, 2026
@AdwaithBatchu AdwaithBatchu deleted the context-menu-3d branch January 28, 2026 16:07
@AdwaithBatchu AdwaithBatchu restored the context-menu-3d branch January 28, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants