Closed sumantkrsoni closed 2 years ago
To plot a CSV file just load it using pandas (or even the csv module if you want), and then plot the columns (numpy arrays) how you want with Mayavi.
@prabhuramachandran Sir, I have gone through the example section of mayavi and I found that data has been generated through numpy.mgrid.
Also, the results are computed on these mgrid data which is not in case of CSV data.
If any simple data [x, y, z, f(x, y, z) ] is available then will it work for volume slice:
mlab.volume_slice(x, y, z, f)
If possible, please suggest to plot a 3d contour without using np.mgrid or how to deal this mgrid step for csv data.
A simple data is attached here.
Thanks in advance!!!! 3Dresult3.csv
Unfortunately, you are going to have to read the documentation or I suggest watching the scipy mayavi tutorial to understand this better. https://www.youtube.com/watch?v=r6OD07Qq2mw
To explain this better, let me say I give you N points with some values, are these points just scattered points? Do they represent a line or a surface or a volume? A visualization system needs to be told what this data represents and so either the software has to make implicit assumptions or ask you to explicitly define these. Visualizing this can be done with a few lines of code but you need to understand this before you do so. Doing that will require spending some time reading the docs or following the tutorial.
In my case, all points are laying on a plane surface.
3Dresult3.csv contains data uniformly laying on a few planes and then stacked vertically.
[[first plane with their data] [second plane with data] [third plane with data] ]
Meanwhile, I am going to lear through the suggested weblink for youtube.
Thanks Sir!!!
So in that case do you have "connectivity" information, in that is there any implicit ordering between one point and the next? If so, you can transform it to a form compatible with mgrid. Otherwise if there is no order/periodicity, you will need to generate the volumes using a Delaunay triangulation which is available as a filter. You can load up the x, y, z points as a scalar_scatter run a delaunay3d filter and then visualize that. The tutorial has that exact example somewhere.
First of all, Thank you for a prompt response/support. I am learning mayavi through the youtube link which is elaborated nicely. Also, I am getting interest over it after exploring its ability. It is perfectly suitable for my research area.
Yes Sir, spatial datas are sampled periodically. Additional to it, Sir, how can we transform 3d periodical data to a sructured grid data using numpy.mgrid?
e.g. x, y, z are the 10 spatial data points, and u = sin(x).
finally we have [x, y,z, u] , I am interested in 3d contour plot. So please give me hint for converting simple lised data to a structured data using mgrid command.
It will help me learn it. Thanks Sir
import numpy as np
from mayavi import mlab
x = numpy.linspace(0,1,10)
y = x
z = x
u = sin(x)
Please first think about the geometry of your data. You seem to have not fully understood mgrid (use meshgrid if you prefer but beware of the ordering of points). Look at the shape of the arrays produced with mgrid and contrast with that of linspace. If you are unable to find a pattern in the ordering of the points and want to brute force it, if you look at the slides 07_filters_modules.ipynb there is even a case of randomly sampled points for which a contour is taken. There are some massive limitations of that approach.
Thanks @prabhuramachandran Sir, I am looking into the mayavi contents carefully. I'll get back after getting insights about it.
Thanks for your valuable support Sir.
@prabhuramachandran SIr, I have gone through the youtube link for mayavi tutorial and also, I have implemented your suggestions for grid interpolation for the present data:
I would request you to take a look at the script mentioned below for correct direction approval.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.interpolate import griddata as gd
#read values
data = pd.read_csv('darcy3d100fem.csv')
x = data['x'].to_numpy()
y = data['y'].to_numpy()
z = data['z'].to_numpy()
T = data['T'].to_numpy()
#generate new grid
X,Y,Z=np.mgrid[0:1:10j, 0:1:10j, 0:1:10j]
#interpolate "data.v" on new grid "inter_mesh"
T = gd((x,y,z), T, (X,Y,Z), method='nearest')
mlab.clf()
#Plot values
fig = plt.figure()
ax=fig.gca(projection='3d')
sc=ax.scatter(X, Y, Z, c=T, cmap=plt.hot())
mlab.contour3d(T, contours=4, transparent=True)
plt.colorbar(sc)
plt.show()
Also, I would like to add thanks to the Query Asked on StackOverflow
Also the final plot is:
Hello everyone, Any example, that uses numeric data to plot a 3d plot from a CSV file?
I have a CSV file that includes the data for [ x, y, z, f(x,y,z) ]
kindly suggest a 3d plot using such data.