2016-12-05 7 views
0

Ich muss Kugeln zeichnen, die in Transparenz, Radius und x, y, z-Koordinaten variieren.Plotten einer Oberfläche (Kugel) in Matplotlib, zentriert auf andere Koordinaten als 0,0,0

Ich bin in der Lage, die Kugeln zu plotten und Transparenz (Alpha) -Werte und Radiuswerte (die ich für dieses Beispiel in Zufallszahlen geändert habe) zu ändern, aber ich konnte nicht herausfinden, wie zentriere die Kugeln um andere Koordinaten als 0,0,0.

Wie zentriere ich eine Kugel um andere Koordinaten als 0,0,0 mit Pythons Matplotlib Bibliothek?

Hier ist, was ich bisher habe;

from __future__ import print_function 
from mpl_toolkits.mplot3d import axes3d 
import matplotlib.pyplot as plt 
import numpy as np 
import time , random 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 
ax.set_xlim3d([100.0, 0.0]) 
ax.set_xlabel('X') 
ax.set_ylim3d([0.0, 100.0]) 
ax.set_ylabel('Y') 
ax.set_zlim3d([0.0, 100.0]) 
ax.set_zlabel('Z') 
ax.set_title('pFC-amygdala-insula') 

wframe = None 
tstart = time.time() 
for num in range(100): 
    oldcol = wframe 
    r = random.randint(1, 20) 
    alpha = 1.0/random.randint(25, 100) 
    u = np.linspace(0, 2 * np.pi, 100) 
    v = np.linspace(0, np.pi, 100) 
    x = r * np.outer(np.cos(u), np.sin(v)) 
    y = r * np.outer(np.sin(u), np.sin(v)) 
    z = r * np.outer(np.ones(np.size(u)), np.cos(v)) 
    sphere = ax.plot_surface(x, y, z, color='b', alpha=alpha) 
    if oldcol is not None: ax.collections.remove(oldcol) 
    plt.pause(.001) 

print('Duration: %f' % (100/(time.time() - tstart))) 

Antwort

1

Fügen Sie einfach die Koordinaten des Mittelpunkts zu x, y und z hinzu.

x = r * np.outer(np.cos(u), np.sin(v)) + center_x 
y = r * np.outer(np.sin(u), np.sin(v)) + center_y 
z = r * np.outer(np.ones(np.size(u)), np.cos(v)) + center_z 
+0

Großartig, danke !! – user1454024

Verwandte Themen