Application of Gnuplot figure as transparent on top of image - plot

I would like plot on the top of png figure as transparent and no axes in Gnuplot. If legend can be fitted there, it would be great.
Its code which is based on many discussions of mine in gnuplot here
set xrange [2014:2050]; set yrange [40:125]; set datafile separator " -";
set key autotitle columnhead;
set terminal qt size 560,270;
set offset 1,1,0,0; d(x) = -0.504 * x + 1097.984;
c(x) = 83.3; inc(x) = 0.439 * x - 800.65;
plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror;
which produces this figure
which I want to be applied in this Figure at (2014, 83.3) or just hit starting point approximately.
Source of the figure: Energy visions for Finland 2030, VTT and p. 25 here.
Attempt based on Christoph's comment and his answer here.
Readable code
set terminal qt size 560,270;
set margins 0,0,0,0;
set multiplot;
# Just plotting here
set xrange [2014:2050];
set yrange [40:125];
set datafile separator " -";
set key autotitle columnhead;
set offset 1,1,0,0;
d(x) = -0.504 * x + 1097.984;
c(x) = 83.3; inc(x) = 0.439 * x - 800.65;
plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror;
set tmargin at screen 0.2;
set bmargin at screen 0.15;
unset border; unset tics;
unset key;
set autoscale xy;
plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage;
unset multiplot;
where the picture is kulutus_energia_suomi_90_30.png, the same as in the body.
Wanted output draft
One-liner
set terminal qt size 560,270; set margins 0,0,0,0; set multiplot; set xrange [2014:2050]; set yrange [40:125]; set datafile separator " -"; set key autotitle columnhead; set offset 1,1,0,0; d(x) = -0.504 * x + 1097.984; c(x) = 83.3; inc(x) = 0.439 * x - 800.65; plot d(x) t "Decreasing -0.5\%/yr", c(x), inc(x) t "Increasing +0.5\%/yr", for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror; set tmargin at screen 0.2; set bmargin at screen 0.15; unset border; unset tics; unset key; set autoscale xy; plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage; unset multiplot;
I get

Ok, so here you go.
The steps I did where:
Plot the png as full-size background image (I choose the terminal window size to be exactly that of the original image):
set terminal qt size 845,578
set multiplot
# plot the png as full-size background image
set margins 0,0,0,0
set autoscale xfix
set autoscale yfix
plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage
Check the position of the plot borders in the image and set gnuplots margins accordingly, so that the xrange of [2014:2040] is located at the correct position in the image. For the yranges I used the same as in the png (top is probably 110).
The full script is
set terminal qt size 845,578
set multiplot
# plot the png as full-size background image
set margins 0,0,0,0
set autoscale xfix
set autoscale yfix
plot 'kulutus_energia_suomi_90_30.png' binary filetype=png with rgbimage
# now plot the lines on top
height = 578.0
width = 845.0
# borders in pixel
left = 50.0
right = 646.0
top = 515.0
bottom = 96.0
set tmargin at screen top/height
set bmargin at screen bottom/height
# get the position of 2014 on the png, assumes that left is 1990 and right is 2040
set lmargin at screen left/width + (right - left)/width * 24.0/50.0
set rmargin at screen right/width
set xrange [2014:2040]
set yrange [0:110]
set datafile separator " -"
d(x) = -0.504 * x + 1097.984
c(x) = 83.3
inc(x) = 0.439 * x - 800.65
unset key
unset tics
unset border
plot d(x) t "Decreasing -0.5\%/yr" lw 2, \
c(x) lw 2, \
inc(x) lw 2 t "Increasing +0.5\%/yr", \
for [i=2:6:2] "model1_range_linear.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror
unset multiplot
With the result
I took the data file from Plot from two files with errorbars for Gnuplot, don't know if they are the correct ones.

Related

gnuplot - Properly clipping a 3D plot (splot)

Disclaimer: I am totally new to Gnuplot, so I am probably missing something obvious...
For a presentation that I have to give, I am trying to use Gnuplot for creating an interactive version of this plot.
Up to now, I have come up with the following code:
set hidden3d
set isosamples 40
set border 4095
set xrange [-1 : 5]
set yrange [-3 : 3]
set zrange [-10 : 10]
set xtics 2
set ytics 2
set ztics 2
f(x,y) = x**2 + y**2 * (1 - x)**3
splot f(x,y)
pause -1
However, at the boundary of the plot (specifically, at the boundary with respect to the z-axis) the plot gets truncated in a way that I find quite ugly; see below. What I would like is essentially that all the lines get drawn as if my plot range would be (e.g.) -50 : 50, but then in the end only the "intersection" of the plot with the box [-1:5] x [-3:3] x [-10:10] should actually be shown. What seems to be happening right now is that any "plot segment" that has at least one point outside the box determined by xrange-zrange gets not drawn at all.
(How) can I change this?
Answering from the future, sort of, so this may not count...
Versions of gnuplot through 5.2 cannot do exactly what you want. However the development version 5.3 does this by default so long as you use a pm3d surface rather than a hidden3d surface. Here is your plot as rendered by the current development code:
set border 4095
unset colorbox
set view 56, 15, .75, 1.75
set samples 40, 40
set isosamples 40, 40
set xyplane 0
set grid x y z vertical
set pm3d depthorder border linewidth 0.100
set pm3d clip z
set pm3d lighting primary 0.8 specular 0.3 spec2 0.3
set xrange [-1 : 5]
set yrange [-3 : 3]
set zrange [-10 : 10]
set xtics 1 offset 0,-0.5
set ytics 1 offset 0,-0.5
set ztics 5
f(x,y) = x**2 + y**2 * (1 - x)**3
splot f(x,y) with pm3d fillcolor "cyan"
The key is the command set pm3d clip z. This will be the default in future versions but is not supported in version 5.2. You can build from the current git source repository on gnuplot.sf.net or wait for the release of version 5.4 expected in Spring 2020.
Maybe you can the following line of code to force the zrange.
set ticslevel 0

How can i limit polar grid in gnuplot?

My data is in polar coordinates and when i plot them and try to add the polar grid it will be complete circles but my data is only from 0-60 degrees.
How can i limit the grid only from 0-60 degrees only, and not a complete circle?
I am not aware of a built-in feature for this. However, as a workaround, one might use the multiplot in order to draw the grid lines manually.
For example:
set term pngcairo enhanced size 800,800
set output 'fig.png'
set angles degrees
set multiplot
set lmargin at screen 0.1
set tmargin at screen 0.9
set rmargin at screen 0.9
set bmargin at screen 0.1
set samples 1000
unset border
R_max = 1
dR = 0.2
phi_max = 60.
dphi = 15
set xr [0:R_max]
set yr [0:R_max]
set xtics out nomirror
unset ytics
set style line 42 lc rgb '#666666' dt 3
unset key
plot \
for [i=0:phi_max/dphi] (x>=0&&x<=R_max*cos(i*dphi))?tan(i*dphi)*x:1/0 w l ls 42
set polar
set trange [0:phi_max]
unset raxis
unset rtics
plot \
for [i=1:ceil(R_max/dR)] i*dR<=R_max?i*dR:1/0 w l ls 42
unset raxis
unset rtics
plot cos(t) w l lw 2 lc rgb 'dark-red'
produces:

Labels overlap in gnuplot

Having a data file I want to add labels to my bar plot, but unfortunately the labels overlay above the first bar and I could not figure out how to add an offset to each label:
set xrange[0:30]
set y2tics font "Arial,8" mirror
#set y2tics rotate # rotating the y2ticks alongside with the y-axis
set xtics font "Arial,6"
#set datafile separator "\t"
set boxwidth 0.5 absolute # balkengroesse
set bmargin 0.6
set tmargin 0
set lmargin 0.9
set rmargin 0
set title "RTF History Analysis" font"Arial,9"
set ylabel "Max RTF" font"Arial,9" noenhanced
#set xlabel "Timestamp" font"Arial,9" noenhanced
#set xtics rotate 90 # turn the text to the vertical position
set style data boxes # boxplot
set style fill solid 0.5 noborder
set multiplot layout 3,1 # 3x vertical 1x horizontal
set grid xtics y2tics
set logscale y
set grid my2tics
set yrange[0.001:6500]
set logscale y2
set my2tics 10
unset ytics
set format "10^{%L}"
set xtics rotate by 50 offset -4.5,-3.00
set format y
plot "history_file.txt" u 7:xticlabels(2) w boxes lc rgb"blue" notitle, \
"history_file.txt" u 7:2:3 w labels rotate left font "Arial,6" lc rgb"blue" notitle
Part of data file:
recipe.rcp 14-03-2017-12:10 top 0.00656997498323 0.0074438616489 rx 0.00791297772894
recipe.rcp 14-03-2017-15:55 cibasic 0.00665396222124 0.00770821200216 tx 0.00938002006172
recipe.rcp 14-03-2017-16:27 cibasic 0.00654659192121 0.00791088142395 tx/tx_ 0.010395539525
recipe.rcp 15-03-2017-14:44 ci 0.0106795993772 0.0114679721169 top 0.0128018372288
recipe.rcp 15-03-2017-14:58 sens 0.0101868323628 0.011261329309 tx 0.0131594769347
Try
plot 'data' u 7:xticlabels(2) w boxes, '' u (column(0)):(.5):3 with labels
to place the labels with the boxes, all at the same height (y = 0.5).
To have the labels follow the box height, try
plot 'data' u 7:xticlabels(2) w boxes, '' u (column(0)):(0.01 +$7):3 with labels

Gnuplot 3D plotting from file, not enough detailed values on x-,y-, and z-ticks

I have a simple data I want to plot as 3D plot (3 columns divided by a comma):
33.26,0.0000001,1
67.02,0.0000010,2
101.64,0.0000100,3
137.53,0.0001000,4
175.06,0.0010000,5
214.59,0.0100000,6
256.47,0.1000000,7
301.09,1.0000000,8
348.78,10.0000000,9
399.92,100.0000000,10
454.87,1000.0000000,11
513.99,10000.0000000,12
577.65,10000.0000000,13
646.22,10000.0000000,14
720.05,10000.0000000,15
799.51,10000.0000000,16
884.96,10000.0000000,17
976.77,10000.0000000,18
1075.29,10000.0000000,19
1180.89,10000.0000000,20
1293.92,10000.0000000,21
1414.77,10000.0000000,22
1431.83,10000.0000000,23
1449.15,10000.0000000,24
1466.97,10000.0000000,25
1485.79,10000.0000000,26
1505.97,10000.0000000,27
1527.88,10000.0000000,28
1551.87,10000.0000000,29
1578.3,10000.0000000,30
1607.56,10000.0000000,31
1639.98,10000.0000000,32
1675.95,10000.0000000,33
1715.82,10000.0000000,34
1759.96,10000.0000000,35
1808.72,10000.0000000,36
1862.49,10000.0000000,37
1921.6,10000.0000000,38
1986.44,10000.0000000,39
2057.35,10000.0000000,40
2134.71,10000.0000000,41
2218.87,10000.0000000,42
2310.2,10000.0000000,43
2409.06,10000.0000000,44
2515.83,10000.0000000,45
I wrote a simple script to plot the above data:
#!/usr/bin/gnuplot
set palette rgbformulae 33,13,10
set datafile separator ","
set terminal postscript eps size 10.5, 5.62 enhanced color font 'Helvetica,20' linewidth 2
set output 'test.eps'
set xlabel "time [s] (no operation)" offset -4, 0, 0
set xtics left offset 0,-0.3 rotate by 45 right
set xrange [0:400]
set ylabel "ranges" offset 2, 0, 0
set ytics left offset 0,-0.5
set zlabel "devices" offset -4, 0, 0
set zrange [0:50]
set autoscale
set title " "
set key inside left top;
set dgrid3d 30,30
set hidden3d
set style line 1 linecolor rgb '00FF00' linetype 4 linewidth 1
splot "data.csv" u 1:2:3 title "" with lines palette
And my output:
As you all can see, the output image (or, I should say), the x,y and z ticks on axis x,y, and z are not enough detailed. It is hard to say that the output image was plotted with this data.
Is there a way that would let me manipulate the x,y, and z ticks, to be taken from file, in some elegant way?
I also would like the image to be more readable with new x,y, and z ticks, so I think that the 10000.0000000 value should appear only once, when it appeared for the first time in data file.
Thank you.
Not exactly an answer to your question, and it is my personal opinion, but you might be interested in the ideas:
The data seems not to be grid data, so I would not use a surface plot of any kind.
Plotting only the datapoints in 3d does not give a useful picture, it is only a single line somewhere in space. I would try to use a 2D plot which contains the height information as color.
I would use a logscale for the y-axis.
This leads to the following script:
set terminal pngcairo
set output 'test.png'
set datafile separator ","
set palette rgbformulae 33,13,10
# Set margins to keep colorbox label inside the picture
set lmargin screen 0.12
set rmargin screen 0.85
set xlabel "time [s] (no operation)"
set ylabel "ranges"
set cblabel "devices"
unset key
set yrange [1e-8:1e5]
set ytics format "1e%+T"
set logscale y
set view map
set cbrange [0:50]
set zrange [0:50]
splot "data.csv" u 1:2:3 w p pt 7 palette ,\
"data.csv" every 5::4 u ($1+0):($2/3):(0):($3 != 30 ? 3 : "") with labels
It also prints the z-labels of some datapoints, skipping 30 for spacing reasons.
This is the result:

Gnuplot plot 2D matrix with image, want to draw borders for each cell

I want to plot a 18x18 matrix with gnuplot. Here is my codes:
set size ratio 1
set palette gray negative
set xrange[-0.5:17.5]
set yrange[-0.5:17.5]
set cbrange[-0.2:0.8]
set xtics 0,1,17
set ytics 0,1,17
set xtics offset -0.5,0
set title "Resolusition Matrix for E"
plot "Mat" matrix w image noti
Then I got a fig like this:
Now I would like to add borders to each cell, which will look like this:
Thank you.
For your case you can set one minor tic, which then lies on the border between two pixels, and draw a grid on them:
set size ratio 1
set palette gray negative
set autoscale xfix
set autoscale yfix
set xtics 1
set ytics 1
set title "Resolution Matrix for E"
set tics scale 0,0.001
set mxtics 2
set mytics 2
set grid front mxtics mytics lw 1.5 lt -1 lc rgb 'white'
plot "Mat" matrix w image noti
Note, that set grid front also brings the tics to the front. To avoid that you can scale the tics to 0. For the minor tics you must use a very small number, 0 would omit the grid lines on the minor tics.
The result with 4.6.3 is:
EDIT: In order to control the grid lines and tic labels independently, you can use the unused x2 and y2 to draw the grid (inspired by an answer to How do I draw a vertical line in gnuplot?):
set size ratio 1
set palette gray negative
# grid lines
set x2tics 1 format '' scale 0,0.001
set y2tics 1 format '' scale 0,0.001
set mx2tics 2
set my2tics 2
# labeling
set xtics 5 out nomirror
set ytics 5 out nomirror
set grid front mx2tics my2tics lw 1.5 lt -1 lc rgb 'white'
set xrange[-0.5:39.5]
set yrange[-0.5:39.5]
set x2range[-0.5:39.5]
set y2range[-0.5:39.5]
plot "Mat" matrix w image notitle
With gnuplot version 4.6, this requires setting explicit ranges, so that the x and x2 (unused!) are equal. The information might be extracted with stats from the data file.
Using version 5 allows you to use set link. Instead of all the set *range stuff. You could use:
set autoscale fix
set link x
set link y
Result:

Resources