Gnuplot: How to continue a pm3d plot to the outside of the set range? - gnuplot

I have a problem with plotting my data points with pm3d in gnuplot. In my data file, the points (2-dim domain) are not rectangular aligned, but parabolic as shown in this figure, where the data points are not aligned exactly above each other. My goal is to create a heatmap with pm3d for a specific xrange where the heatmap is continued to the borders of the selected xrange.
What I did:
Plotted the data set with pm3d using the following minimal code example:
set terminal qt
set xrange [-0.25:1.00]
set view map
splot "data.txt" u 1:2:3 with pm3d
What I got:
A heatmap of my data file, but with ugly corners at the border points at where I cut my x-domain, because the border points are not aligned "above" each other.
What I expected:
A heatmap where the "heat" values are continued to the real border of the domain as it is the case for a simple "with lines" plot, shown in this figure.
My attempts so far to achieve what I expected:
I tried several pm3d options, including the option clip1in, which only requires 1 clip of a "heat rectangle" to be inside the domain, but the result was that the corners are no laying outside of the domain, which doesn't solve the problem unfortunately.
Additional information:
OS: Ubuntu 20.04
$ gnuplot -V
gnuplot 5.2 patchlevel 8
If anybody knows how I achieve what I'm trying to do, it would be nice to share that knowledge!
Cheers!

Gnuplot 5.4 does offer this sort of smooth clipping on the z coordinate, but unfortunately that doesn't help because you want clipping on x in this case.
Here is an example of performing x clipping by manual intervention.
The complicated expression for the x coordinate is just to generate points
with a non-orthogonal grid.
xclip(x) = x > 6. ? 6. : x # clip x to maximum value of 6.
f(x,y) = sin(sqrt(x*x + y*y)) # some function to plot
set sample 21; set isosample 21
set view map
set xrange [-6 : 6]
unset key
set multiplot layout 1,2
set title "No clipping"
splot '++' using ($1+$2*$2/10.) :($2):(f($1,$2)) with pm3d
set title "Manual clipping at x=6"
splot '++' using (xclip($1+$2*$2/10.)):($2):(f($1,$2)) with pm3d
unset multiplot

Related

Difference between drawing using Gnuplot and OriginLab

I have two data files, qebands.agr and ex1_band.dat. When I plot them using OriginLab I got directly this figure:
On the other hand, someone used Gnuplot with the following script:
set xtics nomirr
set x2tics
set xrange [*:*] noextend
set x2range [*:*] noextend
plot 'qebands.agr' w l, 'ex1_band.dat' axes x2y1 w l
and get:
I haven't used Gnuplot before.
Could anyone tell me why the two figures are different? i.e., why the scale the x-axis is different in both figures?
Depending on which image is the desired one...
Remove axes x2y1 in the second part of the gnuplot command and you will get a similar plot as the Origin one.
You are explicitly specifying that 'ex1_band.dat' is plotted to axes x2y1 (x2 = top x-axis, y1 = left y-axis).
Per default, gnuplot autoscales both x-axes independently, unless you link them (check help link).
Origin is plotting both files relative to x1y1 axes.

Trying to plot contours on Mac using the same script I use on windows on gnuplot

I have an issue with gnuplot on Mac. On windows everything seems fine I can easily draw contours on a "heat map". But on my Mac using the same script I can plot the map but not the contours on top of it.
https://imgur.com/a/x00bFnJ here is the two images. One with the contours is on Windows, other one is on Mac.
https://justpaste.it/6ws4h and here is the script.
I tried grid3d but they seem like not nearly accurate as the ones I have plotted on windows.
I cannot explain the difference between your two machines, but I think I can see where the problem arises. The following lines from your script are inconsistent with producing a plot with both a surface and contours shown:
set style data pm3d
set style function pm3d
set pm3d explicit at b
splot DATA with pm3d # command simplified
The issue is that both the default style and the explicit plot command specify pm3d, which is a filled-area surface plot. But contours need to be drawn with lines or with labels. You need some combination of defaults and explicit styles that allows you to mix both a surface and lines. I think either of these would do the trick:
set pm3d explicit
set style data lines
splot DATA with pm3d
or
set pm3d implicit
splot DATA with lines
Well! I will answer my own question.
set pm3d map
set contour surface
set cntrparam ...
sp "DATA" u 1:2:3 with pm3d lw 2,"" u 1:2:3 with lines nosurf
Solved my problem.!

Is there a bug in Gnuplot 5.2 (patch 5) with `multiplot` command?

I'm running Gnuplot version 5.2, patch level 5, and I am getting unexpected behavior from the multiplot command. In efforts to produce two plots, one smaller and superimposed on the larger one, I am using the multiplot environment in the following way:
reset
set multiplot
set origin 0,0
set size 1,1
plot "first_file.dat"
set origin 5,5
set size 0.5,0.5
plot "second_file.dat"
unset multiplot
When I first run set multiplot an empty canvas shows up that I close. Then, when I enter unset multiplot nothing happens. From following instructions online it seems like the unset command is supposed to produce the plot, but it doesn't. Am I doing something wrong, or is there a potential bug with this version?
Why do you close the empty canvas? You won't see anything until you plot your data. The following code gives two superimposed plots. However, the set origin coordinates are relative to the screen (ranging from 0.0,0.0 to 1.0,1.0). If you want to place the second graph relative to some coordinates of the first graph, this probably would require some calculations.
reset session
set colorsequence classic
set multiplot # will show an emtpy canvas
plot sin(x) lt 1 # will show the first plot
set origin 0.1, 0.45 # origin coordinates are relative to the screen
# not to the coordinates of the first plot
set size 0.5,0.5
plot cos(x) lt 2 # will show the second plot on top of the first plot
unset multiplot
Result (wxt terminal):

Gnuplot segmentation fault

I use ubuntu 16.04 LTS and gnuplot 5.0 patchlevel 3. This is the data file I have and I want to plot it like a heatmap. When I enter this in gnuplot:
set terminal png size 1200,1000
s=101
set size square
unset tics
unset border
set view map
do for [i=0:0]{
set autoscale fix
set output sprintf("esatad%.0f.png", i)
plot 'itp.txt' u 1:2:3 every:::(i*s)::(s+i*s) notitle w image
}
I get the following error "segmentation fault (core image recorded)" and then gnuplot is closed. But when I change 2 lines of the code and try to plot it as a surface:
set terminal png size 1200,1000
s=101
set size square
unset tics
unset border
set hidden3d
do for [i=0:0]{
set autoscale fix
set output sprintf("esatad%.0f.png", i)
splot 'itp.txt' u 1:2:3 every:::(i*s)::(s+i*s) notitle w l
}
I get this image, which is what I want except that it is not a "heatmap". I guess that's it, I have no idea of what is happening... sorry, I'm really a newbie. Also, I've been warned (in this website) about pm3d and dgrid3d plots in which "the colors in your image will not correspond directly to the data in your file." Therefore w image should be prefered. I don't even know if that is relevant, but anyway, what should I do?
Edit: I forgot to say that the "w image" code generates an image with labels and axis but the plot frame is entirely black...
I don't know why you are getting a segmentation fault; that should not happen. It might be worth trying to update to a more recent version of gnuplot.
It seems to me that you might be off by one in your every statement. The following works for me (gnuplot 5.2.2):
set terminal png size 300,250
s=101
set size square
unset tics
unset border
set view map
do for [i=0:4]{
set autoscale fix
set output sprintf("esatad%.0f.png", i)
plot 'itp.txt' u 1:2:3 every:::(i*s)::(i*s+s-1) notitle w image
}
I had the same problem.
Let's say you have a grid of 10 x 20 data.
If the number of all data lines are not equal, for example, one set has 9 lines and the rest have 10 lines, it will generate a segmentation fault (it shouldn't, however).
Maybe double check data if any line is missing.

Smoothing out contourplot in Gnuplot?

I am trying to plot a simple contour plot (in gnuplot) for the Himmelblau's function using the following code :
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set table 'cont.dat'
splot f(x,y)
unset table
reset
set xrange [-5:5]
set yrange [-5:5]
unset key
p './cont.dat' w l lt -1
I get the following plot result:
There are a few problems with the plot which I wish to eliminate:
It shows some horizontal lines in the plot, I don't know why. How can I remove the horizontal lines?
The contour lines are not too smooth. How can I improve there smoothness?
I feel that both the above problems are connected but can't figure out how. Can you please help me understand and hopefully eliminate the problems?
EDIT 1 : I found the answer to question-2, i.e. improving smoothness. I could do it by increasing the isosample. But I still get a lot of horizontal lines as shown in figure below.
But how to remove these horizontal lines? I just want the contour lines for the levels specified.
Here is how you can plot only the contour lines: You must use unset surface, which plots only the contour lines, and view the plot from above with set view map. See also the 2D contour projection plot from the gnuplot demos.
Smoothing can be achieved with set isosamples, but in some way also using e.g. set cntrparam bspline and similar.
So your script becomes:
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set isosamples 250
unset surface
set view map
set key out
splot f(x,y)
With the result (using 4.6.3):
I was able to solve both the problems. The solution to Problem-2 I already shared in the edit-1 of question.
For Problem-1, i.e. removing the IsoLines from the contour plot, I should have left the initial blocks of data int he cont.dat files which contain the data for the isolines. Instead, I should have plotted from the Data Block 250 onwards (first 250 blocks of data were from IsoLines because of set isosample 250,250 command).

Resources