artifacts in transparent fill when plotting data files with gnuplot [duplicate] - gnuplot

I have noticed that Gnuplot produces ugly artefacts when dealing to filled elements.
One instance is in the palette of the next figure:
Another example is when using filledcurves between two curves defined from points in ASCII files. In this case, you can see that rather than a real solid fill between the lines, the area is filled with number of strips, that only become apparent after zooming quite a bit, but that has very strong impact when rastering the image to png or similar:
This seems to be independent on the terminal. I have tried postscrip, pdfcairo and even tikz. Is there anything that can be done to improve this, or is this a hard limitation of Gnuplot?

Unfortunately, this is an artifact due to antialiasing in the document viewer when you have two filled polygons touching each other. This happens with the filledcurves plotting style, which composes the filled area of many quadrangles, as well as with the pm3d style (as you can see in the colorbox, which shows the same artifacts). See also
problematic Moire pattern in image produced with gnuplot pm3d and pdf output. for a concrete demo case.
There is a workaround, which however is very cumbersome. You must generate a filled polygon object with some script, fill that, use stats to determine the ranges, plot an empty plot (see e.g. Gnuplot - how can I get a figure with no point on it ? (I want to have only the axes, the title and the x- and y- labels)).
I assume, that you have a data file with three columns, and you would plot them with
plot 'test.dat' using 1:2:3 with filledcurves
Using the following very crude python script
from __future__ import print_function
from numpy import loadtxt
import sys
M = loadtxt(sys.argv[1])
print('set object 1 polygon ', end='')
for i in range(0,len(M)):
if (i == 0):
print('from {0},{1} '.format(M[i][0], M[i][1]), end='')
else:
print('to {0},{1} '.format(M[i][0], M[i][1]), end='')
for i in range(len(M)-1,-1,-1):
print('to {0},{1} '.format(M[i][0], M[i][2]), end='')
You can plot the filled curve with
# determine the autoscaling ranges
set terminal push
set terminal unknown
plot 'test.dat' using 1:2, '' using 1:3
set terminal pop
set xrange [GPVAL_X_MIN:GPVAL_X_MAX]
set yrange [GPVAL_Y_MIN:GPVAL_Y_MAX]
eval(system('python script.py test.dat'))
set object 1 polygon fillstyle solid noborder fillcolor rgb 'red'
plot NaN notitle
That, doesn't yet cover the problem with the jagged colorbox :(

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 and unstructured data is it possible

So far, I have been able to generate 2D contour plots using pm3d for a 2D structured data. However, I have got some data files that contains some flow visualisation of an unstructured grid that I am trying to plot next to the structured data. So far, I have found some links pointing to some scripts on how to generate contour plots Link, but it seems that the only way to do it is through dgrid3d, which only generates contours lines rather than the surface flow like this picture .
I am just wondering if there is a better way to generate similar plot using gnuplot tool.
Thank you very much for the help!
It is not correct that dgrid3d only produces lines. It is a preprocessing step for your data, which can subsequent be plotted using any style you want.
Here is an example using a pre-generated set of random points with Gaussian distribution. The code shown should work with gnuplot version 5.2 or newer. A slightly simpler plot command is possible in the current gnuplot version but the one shown still works also.
set view map
unset key
set cbtics format "" # no tic labels on the colorbar
set palette cubehelix negative
#
# Generate a grid from point density of previously-generated Gaussian
#
set dgrid3d 50,50 gauss kdensity
#
# Make all contour lines black
#
set contour base
set cntrparam levels incremental 0,200
set cntrparam firstlinetype 101
set for [L=101:110] linetype L linecolor "black" dashtype solid
set style textbox opaque noborder
set pm3d explicit at b
#
# Order of drawing is important.
# First the surface, then the lines, then the labels
#
splot $random using 1:2:(1) with pm3d, \
'' using 1:2:(1) with lines nosurface, \
'' using 1:2:(1):("") with labels boxed

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

Plotting smooth sphere from discrete data with gnuplot

I have data generated from python code as such:
u, v = np.mgrid[0:2*np.pi:180*1j, 0:np.pi:90*1j]
X = np.cos(u)*np.sin(v)
Y = np.sin(u)*np.sin(v)
Z = np.cos(v)
This is written to a file tmp.dat, and I attempt to plot it in gnuplot with:
set pm3d
set palette
set hidden
splot "tmp.dat" using 1:2:3 with pm3d
However, this gives me:
It's in the general vicinity of what I want, but I'd like a smooth sphere as opposed to this. (My real data is in the same vein; with an enclosed surface I want to have transparency on.) I've tried adding set dgrid3d 50,50 to try and interpolate, however, I don't actually understand what I'm getting from this:
Any help or advice would be enormously appreciated. Changing the data to parametric (with u and v sweep data) is an option, however, I'm not certain how to do that - when I tried, the result was the same.
Not a complete answer, but part of your problem is that "set hidden3d" is not usable here. Gnuplot has two separate subsystems for representing surfaces. One of them, controlled by "set hidden3d", tracks bounding line segments and can remove occluded portions. The other is pm3d, which uses solid-fill quadrangles rather than bounding line segments. pm3d plots do not have the option of removing occluded quadrangles, but you can get a similar effect by depth-sorting them. The relevant command is
set pm3d depthorder
This works reasonably well if the individual quadrangles are approximately square but it gives bad results for long thin quadrangles, since the two ends of the facet can have conflicting depths with regard to neighboring facets.

Gnuplot: line opacity / transparency?

I am using Gnuplot to successfully plot some time series data. However, the series are fairly dense (10,000's of samples in about 5 inches of space), and when I plot multiple series, it is hard to see underneath the series that was plotted on top. Is there any way to make the lines have a bit of opacity or transparency (i.e. make the line transparent so underneath lines are visible)?
Excel has this capability, but I would much prefer to use Gnuplot.
Below is a sample of what I'm talking about. You can't see the red lines under the green lines. I would actually like to add a third time series. I am plotting with the command:
plot [][-3:3] 'samples_all.csv' using 1:7 title 'horizontal' w l ls 1, '' using 1:8 title 'vertical' w l ls 2"
Good news! This has been implemented in gnuplot. Example syntax is
plot x lw 10, -x lw 10 lc rgb "#77000000"
This will plot x as a red line and -x as a transparent black line (it looks gray). The first pair of two characters in the rgb specification define the alpha (transparency) channel ("#AARRGGBB"). The normal syntax ("#RRGGBB") still works.
old (gnuplot < 5.0 or so) answer for reference:
If you want to make lines plotted for time series data, the answer is no (see discussion here). You can't set a line style to be transparent. Transparency only works for filling under curves, and it has to be printed to the right terminal type.
I ran into this problem myself recently, I hope this feature will be added in a future version of gnuplot.
This may be what you're looking for.

Resources