2016-06-11 8 views
1

Ich habe diesem Datensatz3-D-Rechtecke in Matplotlib

500295 152342 25286 
500295 157981 24120.6 
500295 163619 15469.8 
500295 169258 18071.8 
500295 174897 25624.7 
500295 180536 30323.5 
500295 186174 8828.7 
500295 191813 4681.19 
500295 197452 7470.08 
500295 203090 29070.4 
506851 152342 2181.82 
506851 157981 1809.44 
506851 163619 3045.71 
506851 169258 7433.56 
506851 174897 10637.3 
506851 180536 12511.1 
506851 186174 7514.93 
506851 191813 5468.37 

, wo die ersten beiden Zahlen Koordinaten sind und die dritte ist das Gewicht. Ich möchte daraus einen 3-D-Plot machen. Ich bin jetzt mit

W = pd.read_csv('data.txt',sep='\t') 
W.columns = ['X','Y','W'] 
mpl.rcParams['legend.fontsize'] = 10 
fig = plt.figure() 
ax = fig.gca(projection='3d') 

ax.plot(W.X, W.Y, W.W,'o') 
ax.legend() 

plt.show() 

der folgenden Abbildung enter image description here

ich die Punkte, 3-d Rechtecken oder jede andere Form machen möchte ergibt, die von der Unterseite auf den Istwert beginnen sollten. Irgendwelche Hilfe?

danke

Antwort

2

Sie bar3D dafür verwenden können. Arbeiten mit dem zur Verfügung gestellten Daten:

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt 
import numpy as np 

xsize = 1000 
ysize = 4000 
data = np.loadtxt('data') 
x, y, dz = data[:, 0], data[:, 1], data[:, 2] 
dx, dy, z = np.ones(x.shape)*xsize, np.ones(x.shape)*ysize, np.zeros(x.shape) 

fig = plt.figure() 
ax = fig.gca(projection='3d') 

ax.bar3d(x, y, z, dx, dy, dz, color='green') 

plt.show() 

, was zur Folge hat:

bar3D matplotlib plot example

aber bewusst sein, dass matplotlib ist nicht für den Moment, eine gute 3D-Engine. Weitere Informationen hierzu finden Sie unter this post.

+0

Erstaunlich, das funktioniert sehr gut. Vielen herzlichen Dank. –