gnuplot does not draw anything, just axics - gnuplot

I want to draw something transparent.
my script is :
set output 'rcut.png'
set term png
set style fill transparent solid 0.2 noborder
set style circle radius 1
set multiplot layout 1,3 title "Error of the model"
set xlabel 'batch id'
set logscale xy
set format x "10^{\%T}"
set format y "10^{\%T}"
set key autotitle columnheader
#
set ylabel "Energy[eV]"
p 'rcut=3' u 1:4 w circles lc rgb "navy", 'rcut=6' u 1:4 w circles lc rgb "dark-pink"
#
set ylabel "Force[eV/{\305}]"
p 'rcut=3' u 1:6 w circles lc rgb "navy", 'rcut=6' u 1:6 w circles lc rgb "dark-pink"
#
set ylabel
p 'rcut=3' u 1:8 w circles lc rgb "navy", 'rcut=6' u 1:8 w circles lc rgb "dark-pink"
#
unset multiplot
and it returns an empty plot file:
enter image description here
but when i set the term emf, there will be data in the image:
enter image description here
but it is not what i want, the points are not transparent.
I really want to figure out why,thank you

Long answer:
gnuplot can support two different png terminals, one based on the gd graphics library and selected by set term png and a second one based on the cairo graphics library and selected by set term pngcairo. The gd version only supports transparency if you specify set term png truecolor, which creates an output png file with 24bits of RGB color per pixel and another 8 bits of transparency. Otherwise it generates png files that are smaller (8 bits per pixel) because they are limited to 256 colors and no transparency. The cairo version always produces files with 24bit RGB + 8bit transparency per pixel.
Short answer:
Use either set term pngcairo or set term png truecolor.

Related

How to plot a particular solution in the form f(x,y)=0 on Gnuplot

I need to plot a two variable function on Gnuplot when it intersects with 0, that is: f(x,y)=0. It will mean a 2D plot rather than 3D.
My attempt up to now is:
set term cairolatex eps standalone size 6in,6in lw 7
set key box opaque samplen 6
set key spacing 1.5
set key Right
set key height 2
set key width 3
f(x,y)=...
set output 'V.tex'
plot f(x,y)=0 title '\small${\hat{V}=2}$' lc rgb "black"
set out
but it returns function to plot expected.
Just in case, the workaround given in 5.2 section of the Gnuplot FAQ in http://www.gnuplot.info/faq/faq.html does not produce a .tex file that I can compile.
I tried to combine the code from the FAQ (#gdupras's answer) with the code you showed at first.
set term cairolatex eps standalone size 6in,6in lw 7
set key box opaque samplen 6
set key spacing 1.5
set key Right
set key height 2
set key width 3
f(x,y) = y - x**2 / tan(y)
set contour base
set cntrparam levels discrete 0.0
unset surface
set table $TEMP
splot f(x,y)
unset table
set output 'V.tex'
plot $TEMP w l title '\small${\hat{V}=2}$' lc rgb "black"
set out
In my environment, this code generates "V.tex" and I get the following figure (PDF converted to PNG) after compiling.
This is documented in the gnuplot FAQ: http://www.gnuplot.info/faq/faq.html
From that page:
5.2 Implicit defined graphs
Implicit graphs or curves cannot be plotted directly in gnuplot . However there is a workaround.
gnuplot> # An example. Place your definition in the following line:
gnuplot> f(x,y) = y - x**2 / tan(y)
gnuplot> set contour base
gnuplot> set cntrparam levels discrete 0.0
gnuplot> unset surface
gnuplot> set table $TEMP
gnuplot> splot f(x,y)
gnuplot> unset table
gnuplot> plot $TEMP w l
The trick is to draw the single contour line z=0 of the surface z=f(x,y), and store the resulting contour curve to a temporary file or datablock.

Gnuplot, multiple splots with different color palette [duplicate]

This question already has answers here:
Plotting multiple pm3d surfaces each having its own palettes in gnuplot
(2 answers)
Closed 2 years ago.
I have two 3d surfaces. Is it possible to use a different color palette for each surface with splot?
The script that i used and the graph that is produced follow:
set title "Thermal efficiency versus turbine inlet temperature and degree of superheating diagram"
set termopt enhanced
set grid
set key top left
set xlabel "ΔT_{super} [^{o}C]"
set ylabel "T_{3} [^{o}C]"
set zlabel "n_{th} [-]"
#set datafile missing '0.000000000000000000e+00'
#set datafile missing '0.000000'
set hidden3d
set pm3d
set view 60,60
set palette rgb 7,5,15 #black-blue-red-yellow
splot "para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($5) title "Conventional ORC" with lines lt 1 lw 1.5,\
"para_sub_dtsuper_iso_dtppreg_1.txt" using ($1):($2-273.15):($6) title "Regenerative ORC" with lines lt 1 lw 1.5,\
pic_1
On a side not, i would like to know if it is possible to produced mesh color-gradient surfaces like in the picture below:
pic_2
Thank you in advance.
Here is a revised version of the plot that theozh linked to. It shows two surfaces in the same plot, one using color mapping via the built-in palette mechanism and the other effectively doing the same sort of color mapping explicitly. The development version of gnuplot has automated this so that you can construct and use multiple palettes by assigning a name to each one.
#
# Demonstrate construction and use of a separate palette
#
# This method works in 5.2 but requires "lc rgb variable"
# rather than the more natural "fillcolor rgb variable".
# "set pm3d interpolate" breaks the color mapping of this method
#
# This creates a palette equivalent to
# set palette defined (0 "dark-blue", 1 "white")
#
array blues[256]
do for [i=1:256] {
blues[i] = int( (0x7f + (i-1)/(255.) * 0xffff80) );
}
#
# This is the equivalent of
# set cbrange [0:5]
blues_min = 0
blues_max = 5
#
# This function maps z onto a palette color
#
blues(z) = (z <= blues_min) ? blues[1] \
: (z >= blues_max) ? blues[256] \
: blues[ floor(255. * (z-blues_min)/(blues_max-blues_min)) + 1]
F1(x,y) = sqrt(x*y)
F2(x,y) = (x*y)**(1./3)
set samples 41; set isosamples 41
set cbrange [0:5]; set xrange [0:5]; set yrange [0:5]
set palette cubehelix negative
unset colorbox
# Needed for proper occlusion of hidden surface
set pm3d depthorder
# Place a thin border around each facet of the surfaces
set pm3d border lc "black" lw 0.5
set title "Top surface uses hand-constructed 'blues' palette via rgb variable\n".\
"Bottom surface uses 'set palette cubehelix negative'"
set title offset 0,1
splot '++' using 1:2:(F1($1,$2)):(blues(F1($1,$2))) with pm3d lc rgb variable \
title "F1(x,y) using 1:2:3:4 with pm3d lc rgb variable", \
'++' using 1:2:(F2($1,$2)) with pm3d \
title "F2(x,y) using 1:2:3 with pm3d"
I apologize for the delayed response. This is what i was looking for. I am grateful to both of you!

Gnuplot: transparency of data points when using palette

Is there a way to plot transparent data points when using palette?
I currently have the following code:
set style fill transparent solid 0.2 noborder
set palette rgb 22,13,-22
plot 'mydata.dat' u 1:2:3 ps 0.3 palette
My feeling is that transparency is overwritten by the arguments of the plot command.
Is there a way to plot transparent data points when using palette?
If you check help palette you will not find (or I overlooked) a statement about transparency in the palette. It looks like you can set the palette in different ways for RGB, but not for ARGB (A=alpha channel for transparency). So, I assume it is not possible with palette to have transparency (please correct me if I am wrong).
As workaround you have to set your transparency "manually" by setting the color with some transparency.
You can find the formulae behind the palettes by typing show palette rgbformulae.
The following examples creates a plot with random point positions in xrange[0:1] and yrange[0:1] and random points size (from 2 to 6) and random transparency (from 0x00 to 0xff). The color is determined by x according to your "manual palette". I hope you can adapt this example to your needs.
Code:
### "manual" palette with transparency
reset session
# These are the rgb formulae behind palette 22,13,-22
set angle degrees
r(x) = 3*x-1 < 0 ? 0: (3*x-1 > 1) ? 1 : 3*x-1
g(x) = sin(180*x)
b(x) = 1-(3*x-1) < 0 ? 0: (1-(3*x-1) > 1) ? 1 : 1-(3*x-1)
set xrange [0:1]
set yrange[-0.1:1.1]
RandomSize(n) = rand(0)*4+2 # random size from 2 to 6
RandomTransp(n) = int(rand(0)*0xff)<<24 # random transparency from 0x00 to 0xff
myColor(x) = (int(r(x)*0xff)<<16) + (int(g(x)*0xff)<<8) + int(b(x)*0xff) + RandomTransp(0)
set samples 200
plot '+' u (x=rand(0)):(rand(0)):(RandomSize(0)):(myColor(x)) w p pt 7 ps var lc rgb var not
### end of code
Result:
New answer for Dev version 5.5
The new function set colormap allows to define a transparent palette. First, one defines the fully opaque palette in the usual way, then creates a copy of it and adds transparency to all points:
set palette rgb 22,13,-22
set colormap new MYPALETTE
transparency = 0.5
do for [i=1:|MYPALETTE|] {MYPALETTE[i] = MYPALETTE[i] + (int(transparency*0xff)<<24)}
func(x,y) = x*y
splot func(x,y) w pm3d fillcolor palette MYPALETTE
Of course, this will also work for points, the command in your case will be
plot 'mydata.dat' u 1:2:3 ps 0.3 lc palette MYPALETTE

Gnuplot: oscilloscope-like line style?

Is it possible in Gnuplot to emulate the drawing style of an analogue oscilloscope, meaning thinner+dimmisher lines on larger amplitudes, like this:?
The effect you see in the oscilloscope trace is not due to amplitude, it is due to the rate of change as the trace is drawn. If you know that rate of change and can feed it to gnuplot as a third column of values, then you could use it to modulate the line color as it is drawn:
plot 'data' using 1:2:3 with lines linecolor palette z
I don't know what color palette would work best for your purpose, but here is an approximation using a function with an obvious, known, derivative.
set palette gray
set samples 1000
plot '+' using ($1):(sin($1)):(abs(cos($1))) with lines linecolor palette
For thickness variations, you could shift the curve slightly up and down, and fill the area between them.
f(x) = sin(2*x) * sin(30*x)
dy = 0.02
plot '+' u 1:(f(x)+dy):(f(x)-dy) w filledcurves ls 1 notitle
This does not allow variable colour, but the visual effect is similar.
Another approach:
As #Ethan already stated, the intensity is somehow proportional to the speed of movement, i.e. the derivative. If you have sin(x) as waveform, the derivative is cos(x). But what if you have given data? Then you have to calculate the derivative numerically.
Furthermore, depending on the background the line should fade from white (minimal derivative) to fully transparent (maximum derivative), i.e. you should change the transparency with the derivative.
Code:
### oscilloscope "imitation"
reset session
set term wxt size 500,400 butt # option butt, otherwise you will get overlap points
set size ratio 4./5
set samples 1000
set xrange[-5:5]
# create some test data
f(x) = 1.5*sin(15*x)*(cos(1.4*x)+1.5)
set table $Data
plot '+' u 1:(f($1)) w table
unset table
set xtics axis 1 format ""
set mxtics 5
set grid xtics ls -1
set yrange[-4:4]
set ytics axis 1 format ""
set mytics 5
set grid ytics ls -1
ColorScreen = 0x28a7e0
set obj 1 rect from screen 0,0 to screen 1,1 behind
set obj 1 fill solid 1.0 fc rgb ColorScreen
x0=y0=NaN
Derivative(x,y) = (dx=x-x0,x0=x,x-dx/2,dy=y-y0,y0=y,dy/dx) # approx. derivative
# get min/max derivative
set table $Dummy
plot n=0 $Data u (d=abs(Derivative($1,$2)),n=n+1,n<=2? (dmin=dmax=d) : \
(dmin>d ? dmin=d:dmin), (dmax<d?dmax=d:dmax)) w table
unset table
myColor(x,y) = (int((abs(Derivative(column(x),column(y)))-dmin)/(dmax-dmin)*0xff)<<24) +0xffffff
plot $Data u 1:2:(myColor(1,2)) w l lw 1.5 lc rgb var not
### end of code
Result:

gnuplot - Filledcurve issues

I have the following gnuplot script:
#!/bin/bash
gnuplot << EOF
set term postscript portrait color enhanced
set output 'temp.ps'
set border lw 0.2
unset key
set size 1,1
set origin 0,0
set size ratio 1
set size 0.47,0.47
set mxtics 2; set mytics 4
f(x,z)=z+5-5*log10(x)
set style fill transparent solid 0.1
set yrange [12:-2]; set xrange[0:10000]
plot f(x,17.55) w filledcurve lc rgb "black", \
f(x,17.5) w lines lt 2 lc rgb "green"
EOF
Which gives me an output like this:
I need two fix two things in this image:
1- the filled zone has a black line which delimitates it and this should go away
2- the filling is covering the x and y tics and this should not happen
Thanks!
To address 1):
set style fill transparent solid 0.1 noborder
To address 2):
set grid noxtics nomxtics noytics nomytics front
As a side note, transparent in your set style fill command does nothing in the postscript terminal as it doesn't support solid transparency.

Resources