How do I import XYZ AND a fourth parameter that adds color to my objects?
Create a material that applies your color ramp depending on the vertex color. That way we dont need to create a separate material for each sphere and can easily manipulate the color ramp in one material and all spheres will change accordingly.



Create the spheres and set the color of all there vertices to your Q-Value

import bpy
import random

mat = bpy.data.materials['Material'] # The name of the Material you created
# create sphere 
bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16, radius=1, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0))

obj = bpy.context.active_object
# apply material
obj.data.materials.append(mat)

mesh = obj.data

# create vertex color map
mesh.vertex_colors.new()

color_layer = mesh.vertex_colors["Col"]

# color all vertecys 
q = random.random() # your Value here
color = [q,q,q,1] 
i = 0
for poly in mesh.polygons:
    for idx in poly.loop_indices:
        rgb = color
        color_layer.data[i].color = rgb
        i += 1


Set your viewport mode to shaded, to actually see the color that's applied by the shader.



If you want to be realy fancy you could export your data as an OBJ file (they are very similar to CSV) with vertex colors. That way you wouldn't even depend on Blender.

GIF of whole process

Run script


Create Shader