CSV file to 3D graph

I have been able to import a CSV file, but I’m having trouble figuring out how to make a 3D surface graph based on the data. Do you have any suggestions?

Hi @yaelmedley , and welcome

TableToPoints + Delaunay2D ?


Hi @yaelmedley

After loading your CSV file in ParaView, you may use the “Table to Points” or “Table to Structured Grid” filters to transform your data.

Hello Francois,

Thank you for your reply. I tried your suggestions, but I didn’t get results that made sense. I have attached my csv file. I don’t know if I have it formated correctly. The top row should be one axis, the left column should be another axis and the energies in the grid should be the third axis. Do you have any suggestions? I’m trying to make a surface plot.

Thank you so much,

azi_to_c5_pre_indole.csv (937 Bytes)

Thanks for the example! I understand that your csv contains only the field value, so the target VTK Data Object should be an image data.

You can easily convert your csv file to a vtkImageData with a python script. We recently published a blog explaining the basic steps:


Thank you Francois,

I am new to Python, so this may take me a while to figure out. After I have made a VTK file, would I load it in Paraview and then follow one of your previous instructions for making a graph?

Thanks again,

Here a quick (& dirty) script to convert your CSV data to vtkImageData:

from vtk import vtkImageData
from vtk import vtkXMLImageDataWriter
from vtkmodules.vtkCommonCore import VTK_DOUBLE
import csv

imageData = vtkImageData()

with open('azi_to_c5_pre_indole.csv', newline='') as csvfile:
    csv_content = csv.reader(csvfile, delimiter=',', quotechar='|')

    row_count = sum(1 for row in csv_content)
    csv_content = csv.reader(csvfile)
    first_row = True
    for row in csv_content:
        if first_row:
            imageData.SetDimensions(row_count, len(row), 1)
            imageData.AllocateScalars(VTK_DOUBLE, 1)
            first_row = False
        for value in row:
            imageData.SetScalarComponentFromDouble(x_index, y_index, z_index, 0, float(value))
            y_index +=1
        x_index += 1

writer = vtkXMLImageDataWriter()

In ParaView I get this visualization:

And after a Warp by Scalar Filter:



Thank you so much. I will let you know how it goes.



Do you know if there is a way of rotating the graph?

Thank you,

Hello Francois,

I tried to run the python code you gave me and I got this error:
Traceback (most recent call last):
File “graph2.py”, line 2, in
from vtk import vtkImageData
ModuleNotFoundError: No module named ‘vtk’

I asked the people at hpc that I am using. They aren’t familiar with vtk. Isn’t something that I need to get access to, and how do I do that?

Thank you,

You should install VTK Python first. The easiest way is using pip: pip install vtk.

More information here:

I don’t have pip installed. Do you think I should try installing vtk another way, or try to install pip first?