





















Ok, so you have your computational output of a set of 2D points. You have been lazy and done the obvious stuff: arrange them in columns, with the first one being the x coordinates, second one the y coordinate, then come the fields, which may be scalar (one column each), or vector (two columns each, one for each coordinate). How to visualize them?
With python, start with
ipython --pylab
Then, read the data
In [4]: dt = loadtxt( ‘1/mesh.dat’ )
In [5]: shape( dt )
Out[5]: (1024, 27)
Notice the last command tells us we have 1024 data points, and 27 fields (well, 25 + positions). For convinience, assign columns to arrays:
In [6]: x=dt[:,0]; y=dt[:,1]; al=dt[:,4]
Now x and y are positions, and “al” is the scalar field for the fifth column (number 4, since counters start at 0 in python).
To visualize the positions,
In [7]: scatter( x , y )
A scalar field may be visualized with a color map:
In [9]: scatter( x , y , c = al )
The “c=” means the color is taken from field al. One may fiddle with colormaps and symbol sizes:
In [9]: scatter( x , y , c = al , cmap= plt.cm.Blues, s=8 )
To know the range we are plotting, produce a color bar:
In [19]: colorbar()
Remember each plotting is overlaid on the previous one, so it is necessary to blank the plot from time to time:
In [11]: clf()
For vector fields, assign coordinates to two separate arrays:
In [20]: vx=dt[:,8]; vy=dt[:,9]
Then, use “quiver” to get a vector plot:
In [22]: quiver( x, y, vx , vy )
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。