Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/68f40a7c-717c-8000-8af6-a222789ef1d8
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: Good — that means the cube and morph are running fine, but the little live XYZ text isn’t updating. === Good — that means the cube and morph are running fine, but the little live XYZ text isn’t updating. Let’s clarify what “live” should mean before I show the correct code path. In your current version the only place that calls update_xyz_display is inside setup_plot(), which happens once per redraw or during morph animation. That means it only ever shows the last spiral point and never changes while you rotate or move the mouse. To make it live, you need to: * listen for motion_notify_event * map the mouse position inside the 3-D axes to data coordinates * update the text box continuously. Below is a small self-contained replacement for the event and update logic that you can drop into your class. It doesn’t change any of your geometry; it just adds a real-time coordinate readout that follows the mouse. ===== Put it anywhere under the existing methods: ===== <syntaxhighlight lang="python"> def on_motion(self, event): """Update XYZ display live as the mouse moves over the 3-D axes.""" if event.inaxes != self.ax or event.xdata is None or event.ydata is None: return # Convert 2-D mouse to 3-D data coords (approximate) # We use the inverse of the current view transform try: x, y = event.xdata, event.ydata # Use z=0 plane approximation for simplicity z = 0.0 self.update_xyz_display((x, y, z)) except Exception: pass </syntaxhighlight> ===== <syntaxhighlight lang="python"> def connect_events(self): ===== """Connect mouse scroll and motion events.""" self.fig.canvas.mpl_connect('scroll_event', self.on_scroll) self.fig.canvas.mpl_connect('motion_notify_event', self.on_motion) </syntaxhighlight> ===== <syntaxhighlight lang="python"> def update_xyz_display(self, point): ===== x, y, z = point self.text_box.set_text(f"X: {x:+.2f}\nY: {y:+.2f}\nZ: {z:+.2f}") self.fig.canvas.draw_idle() </syntaxhighlight> ===== - When you move the mouse across the 3-D plot, the little box in the lower-right corner updates continuously. ===== * During morph animation it still reports the endpoint coordinates as before. * No effect on rotation, morphing, or special views. This version is pure ASCII, no encoding problems. If you’d like the XYZ readout to display the coordinates under the mouse cursor projected on the cube faces instead of a simple (x, y, 0) plane estimate, I can extend it to do that using the full 3-D transform math. Would you like that next?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)