Gnuplot segmentation fault - gnuplot

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.

Related

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 - Trying to create a waterfall/ fence plot

I try to create a nice waterfall map with gnuplot showing the development of an optical spectrum with current. My goal is to achieve something close to this :
A waterfall plot
I have tried this command
splot [][1160:1200][-80:-30] "Waterfall.txt" u 1:2:3 w l lw 3 lc rgb 'black'
The "Waterfall.txt" file has the format suggested in the accepted answer here Gnuplot: fence plot from data.
I have ignored z-data values lower than -80, substituting them with NaN.
The outcome is shown in the next image link.
My attempt
As you can see, compared with the previous figure, this is confusing to the reader. How can I fix it in order for it to be close to the first image and thus more clear to the viewer ?
Edit:
Thanks to #Ethan's answer it worked. The outcome is shown in the figure below. The only problem is the transparency of each fence, that reveals partially the subsequent fences.
The new attempt
Assume twenty 2D files each containing Y and Z:
Gnuplot version 5.2
filename(i) = 'silver.dat'
set pm3d scansauto
set style fill solid noborder
set xyplane at 0
set log z
unset key
splot for [k=20:1:-1] filename(k) using 1:(k):2:(1.0):2 with zerrorfill \
fc "white" lc "black" lw 2
I don't have your data files so I use the same file 20 times for the purpose of illustration. It is based on the zerror demo in the gnuplot distribution and online demo set.
Note that the base of each 'fence' is set to (z=1.0) rather than zero because of the log scale on z.
The figure shown was made using a newer gnuplot. It uses partial transparency and a fancier bounding box that isn't in 5.2

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 png on ubuntu

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.

Gnuplot Expand Plot to Fill Area

I am making a video for my simulation, where each each frame is a picture of the simulation, and a graph. I'm making the graph with gnuplot, and I first run the simulation to determine the x and y ranges to use and then hardcode the range into the plot script. It works okay, but the plot does not use up the entire surface, there is a ton of white space, and the plot is only about 1/4 of the total area. Is there a way to make the plot expand closer to the edges of the boundary, or a way to control the plot placement?
Script:
set term postscript eps color enhanced "Helvetica" 36
set output 'image.eps'
set size ratio 0.8
set logscale x
set xlabel 'Time(Arb. Units)'
set xrange [10:100000]
set yrange [0:1.6]
set y2range [0:0.5]
set ylabel 'Absorption(%)'
set y2label 'Emission'
set format x '%.0e'
set xtics 10, 100, 100000
set key noautotitles
plot 'absorption.dat' axes x1y1 w lines lt 3 lw 5, 'emission.dat' axes x1y2 w lines lt 1 lw 5
Here is what comes out:
I set a grey background so you can see what space is being wasted.
Edit: I've also tried the png terminal, but that seems to make the problem even worse. The plot is shrunk even further. I replaced the top two lines of the script with:
set term png font Helvetica 36
set output 'image.png'
Then this is what comes out:
There are several things involved in the computation of the plot size:
Different terminals have different default canvas sizes. If the defaults don't fit your needs, change the size set terminal ... size ...
The canvas has a fixed aspect ratio (given by the terminals size settings) and you impose an additional constraint with set size ratio... which affects only the plot but not the canvas size. So, if you need this size ratio you must adapt the plot canvas to it.
A third parameter are the margins. Since gnuplot don't exactly know how the labels will be rendered by the terminal, the margins cannot be exact. You can set margins manually with set bmargin ... (for the bottom margin) and equivalently for the other margins.
I would suggest to use a terminal that accept the crop flag
e.g. png, gif, jpeg but also epscairo

Resources