1

I have this dataset

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

where the first two numbers are coordinates and the third is the weight. I want to make a 3-D plot out of it. I am now using

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()

which yields the following figureenter image description here

I would like to make the dots, 3-d rectangles or any other shape, that should start from the bottom to the actual value. Any help ?

thank you

Duccio Piovani
  • 1,410
  • 2
  • 15
  • 27

1 Answers1

2

You can use bar3D for that. Using your provided data:

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()

, which results in:

bar3D matplotlib plot example

But be aware that matplotlib is not, for the moment, a good 3D engine. See this post for more about that.

Community
  • 1
  • 1
armatita
  • 12,825
  • 8
  • 48
  • 49