- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the properties of a picked object in mplot3d (matplotlib + python)?
To get the properties of picked objects in matplotlib 3d, we can take the following steps.
Steps
Set the figure size and adjust the padding between and around the subplots.
Create a new figure or activate an existing figure.
Add an 'ax' to the figure as part of a subplot arrangement.
Make a scatter plot of random data points.
Bind the function *pick_event_method* to the event *pick_event*.
Print x, y and z coordinates of the event.
To display the figure, use Show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Scatter plot ax.scatter(np.random.rand(10), np.random.rand(10), np.random.rand(10), c=np.random.rand(10), cmap='hot', picker=5, s=100) # pick_event_method def pick_event_method(event): ind = event.ind[0] x, y, z = event.artist._offsets3d print(x[ind], y[ind], z[ind]) # Connect pick_event_method with pick_event fig.canvas.mpl_connect('pick_event', pick_event_method) plt.show()
Output
It will produce the following output −
Now, click the objects from the plot and it will display the coordinates of those points on the console.
0.29471404722373373 0.7272382336952506 0.551701540876738 0.7393059098968329 0.880733225356321 0.20733995579556608 0.4055966753557102 0.9709122739514328 0.10116103589732084 0.2781962334047674 0.48531626106129566 0.8573607199598575
- Related Articles
- How to display a 3D plot of a 3D array isosurface in matplotlib mplot3D or similar?
- How to get a subset of JavaScript object's properties?
- How to get a subset of a javascript object's properties?
- How to scale axes in Mplot3d?
- How to change the font properties of a Matplotlib colorbar label?
- How to modify properties of a nested object in JavaScript?
- How to ignore the multiple properties of a JSON object in Java?
- How to get the properties of a driver using JDBC?
- How to duplicate Javascript object properties in another object?
- How to create object properties in JavaScript?
- How to delete object properties in JavaScript?
- How to edit the properties of whiskers, fliers, caps, etc. in a Seaborn boxplot in Matplotlib?
- Filter the properties of an object based on an array and get the filtered object JavaScript
- How to get all the Get-Process properties using PowerShell?
- How to get the size of a json object in JavaScript?

Advertisements