Change color of dgrid3d surface in Gnuplot - gnuplot

Is there a way to change the color of the lines of the surface when using dgrid3d? It seem simple enough but everything I've looked at only speaks of coloring the whole surface using pm3d. I have multiple surfaces on one plot and would like to be able to specify the color of each. For example, one would be red, another would be blue, another would be black, another would be green.

If you have your data available in a file Data.dat then give this a try:
set dgrid3d 10,10
set style data lines
set pm3d
splot "Data.dat" pal
The dgrid3d tells gnuplot how many entries there are in the x- and
y-direction (those are the two comma separated parameters)
The style data lines lets gnuplot plot the result with lines
instead of points
The pm3d fills the surface with a color (if you leave this away you
will just see the lines)
pal makes the lines appear in the color of the specified value
There are much more options you can set, but i find those the most relevant.

Seems like.
set dgrid3d
splot "file.dat" with lines linecolor 4
Where 4 is color you need.
For multiple surfaces you can try
set dgrid3d splines
set table "surface1.dat"
splot "file1.dat"
unset table
unset dgrid3d
for every surface you need.
And after all surface description
splot "surface1.dat" with lines linecolor 4, splot "surface2.dat" with lines linecolor 7 ...

Related

How to show a grid with two filled plots

I am plotting to datasets with 'fillsteps' one below another and I want the plot two show only the area that is a difference between the two
plot [0:1][0:1] x with fillsteps above fill solid not,x**2 with fillsteps above fill solid lc rgb 'black' not
But the grid obviously gets blocked in this case:
Is there any way to create something like a cross-section between the two areas, show the grid and get rid of those nasty artifacts that are seen below?
Ok, basically you want to fill the area between two curves (either lines or steps) and have a grid on top. The set grid front you found yourself, but let me make another suggestion.
For the first case (lines), i.e. a fill between lines, you can simply use 3 columns (check help filledcurves) and then the area will be filled between the curves:
plot '+' u 1:(f1(x)):(f2(x)) w filledcurves
For the second case (steps), I don't see (yet) such an option with filledsteps. Actually, from your option above I assume you are using gnuplot5.5.
In general, I wouldn't call it a "clean" solution if you plot something and partly have to cover it with something else with background color. What if you want a transparent background? A transparent color which covers something colored has not yet been invented ;-), there is no such "invisible" color. For another example check this.
Furthermore, with fillsteps I can also observe the artifacts of vertical gap lines which you see in your graph, but I don't have a good solution to avoid them.
Hence, my suggestion is to plot only there where you need something to plot. Actually, you can mimic the fillsteps behaviour. It's not obvious how to do it, but not too difficult. While you plot line by line, you remember the previous x-value and function values of f1(x0) and f2(x0) in x0, y0 and y2, respectively. You plot with the plotting style boxxyerror (check help boxxyerror) using x:y:xlow:xhigh:ylow:yhigh.
Script: (works with at least gnuplot>=5.0.0)
### plotting style filledcurves and mimic fillsteps "between"
reset session
f1(x) = x
f2(x) = x**2
set xrange[0:1]
set yrange[0:1]
set key noautotitle
set grid x,y front lw 1.3
set style fill solid 1.0 border
set samples 50
set multiplot layout 2,1
plot '+' u 1:(f1(x)):(f2(x)) w filledcurves
plot x1=y1=y3=NaN '+' u (x0=x1,x1=$1):(y0=y1,y1=f1($1),y2=y3,y3=f2($1)):(x0):(x1):\
(y0):(y2) w boxxy
unset multiplot
### end of script
Result: (download the PNG image and check that the background is transparent).
set grid front
works in this case

Plot contours from one graph into another in Gnuplot

I have a data file with four columns X Y Z1 Z2 and I want to create a seperate color plot for each Z but plot contour lines from the first one also into the second one.
First I create a plot for Z1 and the contour file with
set terminal "pdfcairo" enhanced dashed size 5,5
set output "Output1.pdf"
set pm3d
unset surface
set view map
set contour
set cntrparam levels discrete 1.45,1.50
set table 'DATAFILE.contourZ1'
splot 'DATAFILE' using 1:2:3 notitle with lines
unset table
splot 'DATAFILE' using 1:2:3 notitle with lines
unset output
This gives me the color plot with two contour lines along Z1=1.45 and 1.50. So far so good. To load the contours into the second plot I tried
splot 'DATAFILE' using 1:2:4 notitle with lines,\
'DATAFILE.contourZ1' using 1:2:3 notitle with lines
but this only gives me the colorplot for Z2 without any contour lines.
Does anyone know, how I can accomplish this? If it's not possible in such an easy way as I have tried, I'm open for other ways, too :)
Thank you very much!
You have to unset pm3d before saving the table file so that you get a file with only the contour-line points.
Then if you want to plot pm3d and lines you might want to use set pm3d explicit and a splot "contour.txt" with lines, "data" with pm3d.

How do I use a data parameter to set the colour of gnuplot points?

I'm creating a GIF of the movement of random particles and I want to plot the particles as points of a certain colour that relates to the velocity of the particle at a given time. Using gnuplot 4.6.6, how do I make the colour of a point a function of a data value? If possible, I'd like the colours to come from the palette 'rgbformula 21,22,23' and not just from the standard line colours set.
Thanks
You can use the lc palette flag:
set palette rgbformulae 21,22,23
plot 'particles.dat' using 1:2:3 lc palette
type ? linecolor or ? palette for more info.
You can pass a third column to the plot command and linecolor palette. Then, the palette colors are used to encode the value of the third column and the colorbox showing the palette is drawn:
set palette rgbformula 21,22,23
plot "data" using 1:2:3 with points linecolor palette

Output gnuplot legend in separate file [duplicate]

I have an interactive perl script which uses data from mysql to generate many plots through the Chart::Gnuplot package. There are times when the graph size is overloaded with too many plots.
I would option to generate the gnuplot image containing only the legend (no graph).
I don't know if this would help, but...
plot [0:1] [0:1] NaN title "Hello" #Just the label in the legend.
or...
plot sin(x),NaN title "Boo" #Plots sin(x) (properly labelled) and a second label "Boo"
Of course, this still has the border and other things. You can unset those...unset border and unset tics

Plot two datasets on the same graph with gnuplot. One with dgrid3d, the other one without

I'm trying to plot two data sets with gnuplot. They are both (x, y, z) triplets. They are not arranged on a grid. I want to plot one of them using dgrid3d and pm3d. On top of that I want to overlay the other data set but as just scattered points.
To give a more concrete example: I am trying to plot the effect of a cylinder approaching a surface. I want to plot the response of the surface and that's where dgrid3d comes in handy. On top of that, I want to plot the position of the cylinder and I have its circumference as points.
I used:
set dgrid3d 100,100,4
set pm3d
splot "dataset1" with pm3d, "dataset2" with dots
The data set has about 100x100 points, arranged on a near-square, so 100,100 works best here. No matter how I plot the second data set, it always ends up being a square of the same dimensions as the cylinder, instead of a nice circle. When I turn dgrid3d off, I can plot the second data set on its own and the result is a nice circumference of the cylinder.
So my question is: is it possible to plot a 3D graph using two data sets, one using dgrid3d and the other one not using it?
Yes, this is possible, but it is a little more tricky than you might think. The key is to use set table
For your example:
set dgrid3d 100,100,4
set pm3d explicit
set table "interpolated_data.dat"
splot "dataset1" with pm3d #writes the interpolated data to "interpolated_data.dat"
unset table
unset dgrid3d
splot "interpolated_data.dat" with pm3d, "dataset2" with dots
The reason that your attempt didn't work is because when dgrid3d is in effect, All data read in is interpolated to a grid and then plotted using whatever style you specify.
From gnuplot's help dgrid3d
When enabled, 3D data read from a file
are always treated as a scattered data set.
As a side note, this method can also be used to plot contours on top of a pm3d as well.

Resources