Python Forum
Scaled scatter modification - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Scaled scatter modification (/thread-22268.html)



Scaled scatter modification - yvrob - Nov-06-2019

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!


RE: Scaled scatter modification - yvrob - Nov-08-2019

I spent some time on this problem, and still no solution... has anybody an idea?