How can i limit polar grid in gnuplot? - grid

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:

Related

How to set x2label for pm3d plot?

I want to make a pm3d plot with different scales on the x-x2 and y-y2 axes (namely 'optical thickness' and 'real thickness'). I can make the tics different on the axes, but the x2label and y2label are not shown. Could you recommend a solution?
n1 = 1.2
n2 = 1.3
set view map
set link x2 via x*670/2/pi/n1 inverse 2*pi/670*n1*x
set link y2 via y*670/2/pi/n2 inverse 2*pi/670*n2*y
set xlabel "{/Symbol a}=2{/Symbol p}/{/Symbol l}n_1L"
set x2label "L_1(n_1) [nm]"
set ylabel "{/Symbol b}=2{/Symbol p}/{/Symbol l}n_2L"
set y2label "L_2(n_2) [nm]"
set xtics nomirror
set ytics nomirror
set x2tics 100
set y2tics 100
unset colorbox
splot sin(x)*y**2 w pm3d
I have a manual solution with something like:
set label 1 at screen 0.95, screen 0.5 "L_2(n_2) [nm]" rotate by 90
but it is not the best way I think.
Instead of using splot w pm3d you probably could use plot w image.
Right away, I couldn't find any useful information in gnuplot help why there is no x2label in a "3D"-plot. Maybe there is and I just haven't found it.
Script:
### plot a map via "plot w image" instead of "splot w pm3d"
reset session
set xlabel "{/Symbol a}=2{/Symbol p}/{/Symbol l}n_1L"
set x2label "L_1(n_1) [nm]"
set ylabel "{/Symbol b}=2{/Symbol p}/{/Symbol l}n_2L"
set y2label "L_2(n_2) [nm]"
set xtics nomirror out
set mxtics 2
set ytics nomirror out
set x2tics 200 out
set mx2tics 2
set y2tics 200 out
n1 = 1.2
n2 = 1.3
set link x2 via x*670/2/pi/n1 inverse 2*pi/670*n1*x
set link y2 via y*670/2/pi/n2 inverse 2*pi/670*n2*y
unset colorbox
set urange[-10:10]
set vrange[-10:10]
set samples 100
set isosamples 100
plot '++' u 1:2:(sin($1)*$2**2) w image
### end of script
Result:
It was turn out, that is a bug in version 5.2. It will be fixed in release 5.4.4.
https://sourceforge.net/p/gnuplot/bugs/2519/
https://sourceforge.net/p/gnuplot/bugs/2484/

Hierarchial Axis in GNUPLOT

I am trying to plot a figure using GNUPLOT, but I want to have a hierarchical x-axis, it should be six tick points in x-axis with first level of label in x-axis being 32,64,128,32,64 and 128. Here the first 32, 64 and 128 should be grouped as stencil and the second 32, 64 and 128 should be grouped as diamond in second level of label . Current i am doing this as stencil-32, stencil-64, stencil-128, diamond-32, diamond-64 and diamond-128. Is there a way to change it into hierarchical axis lableling?
If I correctly understand what you mean with hierachical axis the following code could be one possible way of many others.
You could simply increase the bottom margin and add some labels. But if you want to have some axis, using multiplot might be an option. You need to make sure that the margins are identical (especially the left margin).
Code:
### hierarchical axis
reset session
$Data <<EOD
1 stencil 32 0.3
2 stencil 64 0.4
3 stencil 128 0.5
4 diamond 32 0.6
5 diamond 64 0.7
6 diamond 128 0.8
EOD
myBottomMargin = 0.12
myColor(col) = strcol(col) eq "stencil" ? 0xff0000 : 0x0000ff
set multiplot
set origin 0, myBottomMargin
set size 1, 1-myBottomMargin
set lmargin screen 0.1
set style fill solid 1.0
set boxwidth 0.8
set yrange [0:1]
plot $Data u 0:4:(myColor(2)):xtic(3) w boxes lc rgb var notitle
set origin 0, 0
set size 1, myBottomMargin
set border 1 # only bottom border
set xtics nomirror
set xrange [0.5:2.5]
set mxtics 2
set xtics 1 add ("stencil" 1, "diamond" 2) scale 0,1
set yrange [0:1]
unset ytics
unset key
plot NaN # dummy plot just for the extra axis
unset multiplot
### end of code
Result:

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 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:

How to control xticks in multiplot mode

As the title says, I want to find a way to control the xtics in multiplot mode. The output is the following
The plots shown in the first two rows are OK. However, the following three suffer from the very same problem. The numbers on the x axes are very close to each other and in some cases overlapping. So, is there a way to fix this? All input is read from external data files and I cannot know beforehand what is the maximum value of t so as to set xrange [0:max] in every plot and then control the xtics. By the way, is it possible in gnuplot to read the external data file before the plot stage and define the maximum value of t in each plot?
Many thanks in advance.
EDIT
The script used to produce the above output is the following:
reset
set term postscript eps enhanced "Helvetica" 20 size 7in, 11in
set output 'plots.eps'
set size 1,1
set multiplot layout 4, 2
unset key
# plotting the time-evolution of the mLCN
set xrange [*:*]
set xlabel 't'
set ylabel 'mLCN'
plot "hh.rli" u 1:3 w l lc rgb 'black'
# plotting the time-evolution of the RLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(RLI)'
plot "hh.rli" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the FLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(FLI)'
plot "hh.fli" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the OFLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(OFLI)'
plot "hh.fli" u 1:(log10($3)) w l lc rgb 'black'
# plotting the time-evolution of the SALI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(SALI)'
plot "hh.sali" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the GALIs
set xrange [*:*]
set xlabel 't'
set ylabel 'log(GALIs)'
plot "hh.gali" u 1:(log10($2)) w l lt 1 lc rgb 'green',\
"hh.gali" u 1:(log10($3)) w l lt 1 lc rgb 'red',\
"hh.gali" u 1:(log10($4)) w l lt 1 lc rgb 'blue'
# plotting the time-evolution of the MEGNO
set xrange [*:*]
set xlabel 't'
set ylabel 'MEGNO'
plot "hh.megno" u 1:2 w l lc rgb 'black'
# plotting the time-evolution of the Spectral Distance (D)
set xrange [*:*]
set yrange [-0.1:4]
set xlabel 't'
set ylabel 'D'
plot "hh.sd" u 1:2 w l lc rgb 'black'
unset multiplot
reset
set terminal windows
quit
You can tell gnuplot to rotate the tick labels with:
set xtics rotate
That'll take more vertical space, though. You can probably find a compromise solution by picking an angle less than 90 degrees with:
set xtics rotate by 45
or whatever angle looks best.
You can try increasing the distance between individual tics. For example, in the bottom left corner plot, instead of showing every 500th tic, you may show every 1000th. This can be easily achieved by using
set xtics 1000

Resources