1

I have a 3D matplotlib graph. When I zoom in, or change the bounds of the graph, points on the graph will still display even when they are outside of the bounds.

Is there anyway for the data in the graph to not display when it is no longer in bound?

I've seen solutions where you can mask the data before plotting so that it doesn't show if it goes out of bounds. But that's not what I want, I need the data to automatically hide if it gets out of bounds or to reappear if it gets back in the frame.

Here's an example graph.

import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = plt.axes(projection ='3d') z = np.linspace(0, 1, 100) x = z * np.sin(25 * z) y = z * np.cos(25 * z) ax.plot3D(x, y, z, 'green') plt.show() 
3
  • Have you considered ax.set_xlim? Please check this example. Commented Nov 3, 2022 at 6:45
  • This issue is being tracked here: github.com/matplotlib/matplotlib/issues/25804 Commented Sep 18, 2023 at 17:37
  • Does this answer your question? Trim data outside 3d plot in matplotlib Commented Sep 19, 2023 at 2:47

1 Answer 1

0

Sadly, Matplotlib's 3D capabilities are rather limited, so I don't believe it's possible to achieve your desired behavior.

However, you can try a plotting library better suited for 3D data, something like Plotly. This will zoom in, automatically hiding the data outside the view.

import plotly.graph_objects as go fig = go.Figure(data=[ go.Scatter3d(x=x, y=y, z=z, mode="lines", line_color="green", line_width=3) ]) fig.show() 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.