Search code examples
3dgnuplotinterpolationwolfram-mathematica

Plotting a 3D density map with colors interpolated between datapoints for large amount of data


I have some data to be plotted (~100k lines) in the form x,y,z,c, where x,y,z are coordinates, and c is a color. The coordinates range between [-0.5,0.5], and the color ranges between [-n,n], where n is changing, but typically is a small number (e.g. 0.0001). I want to color my datapoints red if negative and blue if positive, and the darkness of it should range from very dark (furthest from zero) to white (in the center)... imagine it as a charge distribution, where center is neutral.

My Gnuplot script for plotting it in 3D and coloring it works, and is the following:

set palette defined  ( -0.01 "dark-red", 0 "white", 0.01 "dark-blue" ) 
sp "filename" u 1:2:3:4 w p pt 7 ps 1 palette not

The code produces a nice density map and due to the color of my data is centered around zero, the points are also colored properly.

Instead of having points, I would like to have a colored interpolated density map, where the color (~continuously..) changes between the points. So instead of a dark dot surrounded by lighter dots and then white dots (barely visible as intended), I would like to see a blob of color with changing darkness/intensity from the center.

I cannot really find a solution to it yet. (I accept any freely available software solutions, e.g. gnuplot, but I have also Mathematica)


Solution

  • Using Mathematica one can even achieve better:

    data = Import["your_file_path.txt", "Table"];

    (* Extract columns x, y, z, and c *) extractedData = data[[All, {2, 3, 4, 6}]];

    (* Filter data based on the condition c > -0.0001 *) filteredData = Select[extractedData, #[[4]] > -0.0001 &];

    (* Plot the filtered data with ListDensityPlot3D *) plot = ListDensityPlot3D[filteredData, ColorFunction -> "TemperatureMap", PlotLegends -> Automatic];

    (* Export the plot to a PNG file *) Export["output_plot.png", plot]

    enter image description here