Draw front arrow over image - r

I have the following image using the code
set terminal png
set output 'plot.png'
set xlabel "GC (%)"
set ylabel "Proportion of genome"
set sample 1000
set xrange[0:100]
set yrange[0:]
set boxwidth 1
set style fill solid
set key off
set style line 1 lt 1 lc rgb "#0000FF" lw 3
set style line 2 lt 2 lc rgb "#32CD32" lw 3
Cauchy(x,xo,wi) = (1./pi) * wi / ((x - xo)**2 + wi**2)
plot 'compositionGC.txt' w boxes, 0.368187*Cauchy(x, 41.4226,1.72758) + 0.631813*Cauchy(x, 51.8272, 0.464711) ls 2
set yrange[0:GPVAL_Y_MAX]
set arrow from 47.2,0 to 47.2,GPVAL_Y_MAX front ls 1
replot
I have everything I need except that I want a vertical blue arrow separating the two peaks at 47.2 in the x-axis in the front. I cannot get it to work.

Do not change the yrange and replot.
Use this arrow command before the initial plot:
set arrow 1 from 47.2, graph 0 to 47.2, graph 1 front lc "blue"

Related

How can static plot in gnuplot be converted to recieve updated data?

The aim is to recrate the plot given in the 'gnuplot demo pages' :
make it read data from a data file: txt/csv/dat
when the data/file is updated; the plot updates accordingly..
ie data is added to data file evey 10mins
additional how can processed in a way that only the most recent update in the data file is plotted not the entire feed of data?
.. so is there another way?
My attempts of creating what I thought would be straight forward..hit the wall; all input will be welcome.
I try adding:
plot [0:100] '< head -1 file.dat' using 1:6 with points
***this doesn't output data using the given format.
Above that line of code I then include/ tried:
f(x) = (x == stats_max ? 1:0)
as above....plot "mydatafile.somformat'
pause 3 reread
the message returned was stats cannot be used with polar data
original code given below:
set zzeroaxis; set xzeroaxis; set yzeroaxis
set xyplane at 0
unset border
unset key
unset xtics
unset ytics
set ztics axis
set arrow 1 from 0,0,0 to 1,0,0 head filled lw 1.5
set label 1 at 1.2,0,0 "X" center
set arrow 2 from 0,0,0 to 0,1,0 head filled lw 1.5
set label 2 at 0,1.2,0 "Y" center
set arrow 3 from 0,0,0 to 0,0,21 head filled lw 1.5
set label 3 at 0,0,23 "Z" center
set view 60, 30, 1., 1.75
set multiplot layout 1,3
set view azimuth 0.
set title 'azimuth 0' offset 0,2
splot sample [t=0:20] '+' using (cos($1)):(sin($1)):($1) with lines lw 2
set title 'azimuth 10' offset 0,2
set view azimuth 10.
replot
set title 'azimuth 60' offset 0,2
set view azimuth 60.
replot
unset multiplot```
So each plot will only contain a single point?
Read and plot only the last entry in the file:
plot '< tail -1 file.dat' with points
Read and plot only the first entry in the file:
plot '< head -1 file.dat' with points
Be aware that this can only work if the program writing to the data file closes it after each write. If it holds the file open all the time then gnuplot will probably not be able to see any new data.
Edit:
3D example reading data from a file:
set view equal xy
set zzeroaxis; set xzeroaxis; set yzeroaxis
set xyplane at 0
unset border
unset key
unset xtics
unset ytics
set ztics axis
set arrow 1 from 0,0,0 to graph 1,0,0 head filled lw 1.5
set label 1 at graph 1.1,0,0 "X" center
set arrow 2 from 0,0,0 to graph 0,1,0 head filled lw 1.5
set label 2 at graph 0,1.1,0 "Y" center
set arrow 3 from 0,0,0 to graph 0,0,1 head filled lw 1.5
set label 3 at graph 0,0,1.1 "Z" center
set view 60, 30, 1., 1.75
set multiplot layout 1,3
set view azimuth 0.
set title 'azimuth 0' offset 0,2
splot 'silver.dat' using 1:2:3 with lines lw 2
set title 'azimuth 10' offset 0,2
set view azimuth 10.
replot
set title 'azimuth 60' offset 0,2
set view azimuth 60.
replot
unset multiplot

gnuplot splot with multiple data sets

I have a script that generates a gnuplot file, I have edited so I have 2 sets of data in the same plot. One is multiplied by -1 to change color. However, only one set appears in the plot, the last one stated. The script is the following.
set arrow from graph 0,first 0.61237, graph 0 to graph1,first0.61237,0 nohead front lt -1
set arrow from graph 0,first 1.67303, graph 0 to graph 1,first 1.67303,0 nohead front lt -1
set arrow from graph 0,first 2.53906, graph 0 to graph 1,first 2.53906,0 nohead front lt -1
set arrow from graph 0,first 3.24616, graph 0 to graph 1,first 3.24616,0 nohead front lt -1
set arrow from graph 0,first 3.74616, graph 0 to graph 1,first 3.74616,0 nohead front lt -1
set arrow from graph 0,first 4.74616, graph 0 to graph 1,first 4.74616,0 nohead front lt -1
set pm3d at b
unset surf
set view 180,90
set palette defined (-1 "red",0 "white", 1 "blue");
set grid xtics mxtics ytics
unset border
set xrange [-10:40]
set xtics -10,((40+10)/5),40
set mxtics 3
set yzeroax lt 2
set ytics ("L" 0.0,"K" 0.61237,"G" 1.67303,"L" 2.53906,"W" 3.24616,"X" 3.74616,"G" 4.74616)
set cbrange resto
set cbrange[-1:1]
set colorbox
set terminal png enhanced nocrop size 1920,1080
set out "SPF_NO_SO.png"
splot "specfun.pm3d" u ($1*13.60569806):2:(1*$4/476.70750366666666666666),\
"specfun.pm3d" u ($1*13.60569806):2:(1*$3/573.04673900000000000000)
unset out
Sample image:
The script produces the desired plot only for the negative set. If I flip the order I get the blue one.
Here is a sample data:
data_sample
FYI-these arrays are quite big
as #user8153 pointed out, I also don't see a reason why using splot.
And as #Christoph pointed out it's difficult without knowing how the data looks like,
for example, what's in columns $3 and $4?
By the way, with your plot command ...u ($1*13.60569806):2 aren't you plotting the same function twice on top of each other, i.e. that's why you see either the red or the blue?
Nevertheless, I tried to anticipate what you probably want to do. I scaled the second function and assumed something linear for columns $3 and $4. Please clarify.
With the code:
### start code
reset session
# generate some dummy data
undefine $Data
set print $Data append
do for [n=1:5] {
a = rand(0)*10
b = rand(0)*0.1+0.1
c = rand(0)*20
do for [i=1:100] {
print sprintf("%g\t%g\t%g\t%g",i,(a*sin(b*i-c)),cos(b*i),cos(b*3*i))
}
print "" # insert empty line for data curve separation
}
set print
# print $Data
# end generating dummy data
set palette defined (-1 "red",0 "white", 1 "blue")
set cbrange [-1:1]
plot $Data u 1:2:($3-$4) w l lc palette z
### end of code
You'll get the following:

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:

Linewidth smaller than 1

I would like to plot these data
1 2
2 3
3 5
4 5
5 6
with this code
set ter pdfcairo enhanced color solid
set out "test.pdf"
set xrange [-.5:4.5]
set yrange [.5:6.5]
unset key
plot "test.txt" u 0:1,"" u 0:2, "" u 0:1:(0):($2-$1) with vectors nohead lw 0.5
The line width command seems to work, but it seems not to work with a line width smaller than 1.
this plot is with line width 5:
this plot is with line width 1
this plot is with line width 0.2
as one may notice, there is no difference between the latter two plots. How can I force gnuplot to use a line width smaller than 1?

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