Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scaled scatter modification
#1
Hello,

I am trying to plot a geometry consisting of spherical surfaces in 3D.
There are tens of thousands of those spheres, with given coordinates, radius and color for each of them.

I want to use scatter with a 3D axis (mpl_toolkits.mplot3d.Axes3D) because I did not find a more efficient way to do it in 3D.
However, I would like to see my geometry on scale, meaning that the balls should have the provided radius in the xyz scale (meters).

After doing some research, it seems that the size that I need to provide to scatter is the surface in pt^2, where 1 pt = dpi/72 pixels
I need then to create a new function scatter2 where the surface (of the disk or the sphere, I am not sure...) is given in meters^2, convert it to pixels^2 which is then converted to pt^2.

Does anybody know how to complete this meters^2 => pixels^2 ?

Also, if you have a better (simpler and/or faster to run) solution, I would be happy to hear of it.

Finally, even using scatter, the plot is very slow when I am trying to rotate the geometry. Is it normal? Can I add something to my code so that it accelerates the graphic processing?

Here is my code for now:
from random import random
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

def scatter2(fig,ax,x,y,z,c,s_meters2):
    s_pixels2 = [s_meters2[i]*1 for i in range(len(s_meters2))] # meters^2 => pixels^2,how to do?
    s_pt2 = [s_pixels2[i]*fig.dpi/72 for i in range(len(s_pixels2))] # pixels^2 => pt^2
    ax.scatter3D(x,y,z,c=c,s=s_pt2)

if __name__ == "__main__":
    n_spheres = 50000
    x = [random()*100 for i in range(n_spheres)]
    y = [random()*100 for i in range(n_spheres)]
    z = [random()*100 for i in range(n_spheres)]
    s = [random()*1 for i in range(n_spheres)]
    c = [[random(),random(),random()] for i in range(n_spheres)]
    
    fig = plt.figure()
    ax = plt.subplot(111, projection='3d')
    scatter2(fig,ax,x,y,z,c,s)
Please tell me also if the way it is programmed and the syntax are okay, I am a beginner.

Thank you!
Reply
#2
I spent some time on this problem, and still no solution... has anybody an idea?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Shocked plt.scatter() errors asja2010 0 1,411 Oct-13-2022, 08:15 AM
Last Post: asja2010
  How to invert scatter plot axis Mark17 3 2,447 Sep-22-2021, 04:45 PM
Last Post: jefsummers
  Animated scatter plot maximan 0 1,616 Jan-18-2021, 03:53 PM
Last Post: maximan
  Group scatter plots Mekala 0 1,617 Jul-23-2020, 02:18 PM
Last Post: Mekala
  how to nest loop for 4*4 scatter plot kassamohammed 0 2,544 Jun-23-2020, 09:47 AM
Last Post: kassamohammed
  How to create Custom Buttons for 3D Scatter plots in Plotly? yourboyjoe 0 2,104 Jun-01-2020, 10:58 PM
Last Post: yourboyjoe
  colorbar for scatter shows no negatives values... gil 0 1,513 Apr-15-2020, 12:45 AM
Last Post: gil
  plotly.graph_objs - Scatter mode error sambanerjee 14 8,984 Mar-18-2020, 02:54 PM
Last Post: sambanerjee
  Python script modification rajannn 1 1,876 Oct-06-2019, 07:55 PM
Last Post: micseydel
  List modification returns none Mark17 6 2,827 Sep-02-2019, 05:40 PM
Last Post: Mark17

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020