Gnuplot png on ubuntu - gnuplot

So, I'm using the following code to plot data from a file called "p2.txt":
reset
set terminal png
set size square
set pm3d map
set xrange[0:100]
set yrange[0:100]
set dgrid3d 100,100
do for [i=1:1]{
set output sprintf("a%03.0f.png",i)
splot 'p2.txt' u 1:2:3 every :::(0+i*100)::(100+i*100)
}
So here is the result:
Image
I don't know why or how, but it seems that a part of the gnuplot code is being written over the image, why is that? How do I get rid of this?
I use Ubuntu 16.04 x64 and gnuplot 4.6.

That is the automatic plot key. Use unset key or splot ... title "" to remove it.

Related

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.!

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

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

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.

Setting gnuplot yrange to fit one curve only

I have a Gnuplot script that draws 2 curves from a data file. If I don't specify yrange, Gnuplot sets it so that all the points of both curves fit in the figure. In my case I would like Gnuplot to only care about one of the curve (it does not matter if the other goes out of range, since I'm interested only in the parts of the figure where the second curve gets close to the first one).
I could find out the minimum and maximum values taken by the first curve, and manually set yrange to those values, but my Gnuplot script is intended to run automatically on many data files, producing many figures for which yrange is not the same, so I'm looking for a way to do that automatically.
Thanks
There are different options, depending on the used gnuplot version:
Version 5.0:
The data file which should be excluded from the autoscaling gets a noautoscale parameter:
plot 'first.dat' using 1:2, 'second.dat' using 1:2 noautoscale
Version >= 4.6:
Use the stats command to get the minimum and maximum value of the relavant data file:
stats 'first.dat' using 1:2
set yrange [STATS_min_y:STATS_max_y]
plot 'first.dat' using 1:2, 'second.dat' using 1:2
At least since 4.0:
Use set yrange [] writeback to save the autoscaled ranges from a plot command and set yrange restore to use them for a later plot:
set terminal push
set terminal unknown
set yrange [] writeback
plot 'first.dat' using 1:2
set yrange restore
set terminal pop
plot 'first.dat' using 1:2, 'second.dat' using 1:2

Getting a gnuplot output from a script

I have a script that closes immediately after opening. I've tried pause -1, but then I have an empty window. I've also tried set output but apparently I can't do that with multiplot
Is there a way to set output while using multiplot?
I tried setting output before setting multiplot, but the ps file was blank
Edit: The solution I found most useful was "pause mouse". I was also told I could use set output and just do "plot file1, file2, file3", but I'm having some issues with the syntax for that.
I typically set the output (and terminal) before going in multiplot mode. One thing you may be noticing is that some terminals don't draw the plots in a multiplot until you unset multiplot (see help multiplot).
The following works.
set term post enh color
set output "foo.ps"
set multiplot layout 2,1
plot sin(x)
plot cos(x)
unset multiplot
One issue with multiplot is that often you want to see the plot (e.g. using x11) and also put it in a file (e.g. postscript). The cleanest way to do this is using the load command:
#foo.gp
set multiplot layout 2,1
plot sin(x)
plot cos(x)
unset multiplot
Now you can call this:
set term x11 persist
load "foo.gp"
set term post enh color
set output 'foo.ps'
load 'foo.gp'

Resources