SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Martin D. <mar...@wa...> - 2008年04月30日 16:23:02
Hi,
I would like to generate (or simulate) 3D histogram... How I can do this with matplotlib/pylab (if I can) ?
I tried different ways :
 - 2D histogram in 3D but the result is not usable for me (because I have lot of small bars)
 - generation of bars with, for each bar, 5 Polygons but I didn't success (I don't hunderstand the main principle of the 3D module) and it seems to be slow (I must draw approximatively 300 bars)
 - simulation of bars with large lines (like in Gnuplot, see below) but, again, I don't hunderstand the main principle of the 3D module and I don't know how I can plot set of lines in a 3D environment...
Today, I do this with Gnuplot :
>>> splot "hist3D.dat" with boxes linewidth 10
hist.dat :
0 0 3
0 1 2
0 2 5
1 0 1
1 1 4
1 2 1
2 0 5
2 1 2
2 2 3
Does someone have an idea ?
Thanks
From: martin.druon <mar...@wa...> - 2008年10月31日 15:48:17
Hi,
this is my best result... figure is acceptable when I use a lot of points...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib
import matplotlib.art3d
import matplotlib.axes3d
import pylab
if __name__ == "__main__":
 data_filename = ...
 # We load data
 # 
 # x1 y1 v1
 # x2 y2 v2
 # x3 y3 v3
 # ...
 #
 data_file = pylab.load(data_filename)
 # We get x coordinate
 lstX = data_file[:, 0]
 # We get y coordinate
 lstY = data_file[:, 1]
 # We get data values
 lstV = data_file[:, 2]
 # We create list of lines from (x, y, 0) to (x, y, value)
 lstLines = [[(x, y, 0), (x, y, v)] for (x, y, v) in zip(lstX, lstY,
lstV)]
 # We create the figure
 fig = pylab.figure(1)
 # We get the axe reference
 ax = matplotlib.axes3d.Axes3D(fig)
 # We create a matplotlib line collection
 lines = matplotlib.art3d.Line3DCollection(lstLines, linewidths=5)
 # We add the collection to the axes
 ax.add_3DCollection(lines)
 # Auto scale
 ax.auto_scale_xyz(lstX, lstY, lstV, ax.has_data())
 # Draw
 pylab.show()
 # Bye
 exit(0)
Example of data file :
0 0 -4.49132
0 1 0.676531
0 2 -1.60375
0 3 -0.184649
0 4 0.958887
0 5 -0.165971
1 0 -0.0216472
1 1 0.157346
1 2 -0.372853
1 3 0.2576
1 4 0.654506
2 0 0.139453
2 1 -0.204437
2 2 0.151606
2 3 0.271027
3 0 0.222327
3 1 0.921501
3 2 0.500956
4 0 0.104108
4 1 0.415777
5 0 0.244248
-- 
View this message in context: http://www.nabble.com/3D-histogram-tp16986530p20268667.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /