Gnuplot won't clip my circle plot. Does set clip works? - gnuplot

I am trying to plot a "fat bands" bandstructure and I am having some trouble with gnuplot.
set terminal pngcairo size 1600,1200 enhanced font "Verdana, 40"
set output 'bandplot.png'
set ylabel 'Energy (eV)'
set yrange [-3:3] # set x range of the plot
set border lw 4
set key font ",25" spacing 1.0 samplen 0 at screen 0.55,0.8
set clip
plot 'bands.dat' u ($1):($2) with lines lt -1 lw 5 notitle,\
'bands.dat' u ($1):($2):(0.0015*$3) with circles lc rgb "blue" fs transparent solid 0.25 noborder title "test"
This data is basically a function in black line and over that there is a similar data with variable sized circles. The thing is set clip is not avoiding some of the circles to be drawn outside the graph. Does anyone know how to do it?
Also, I have seen some bug pages and this might not be possible to be accomplished. Thanks!

Works fine for me even without using set clip (tested with 5.0 and 4.6.6):
set xrange [-pi:pi]
set samples 21
plot '+' using 1:(cos($1)):(0.1) with circles fs solid

Related

Gnuplot: set angular grid limits in polar plot

I am trying to make a wedge-shaped plot in polar coordinates spanning from 0 to 60 degrees. Something like the following figure: Wedge-plot I want
However, the command "trange" is used for the range of the plot, not of the grid itself, and I always end up with the full-circle grid, like this: Same plot but with full grid.
Is there a simple command to set the limits in the angle variable? Here is the code I used to plot the former figure in gnuplot 5.2
set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 600, 400
set output 'polar1.png'
unset key
set border 4096 lt black linewidth 1.000 dashtype solid
unset xtics
unset ytics
set size ratio 1 1,1
set raxis
set ttics 0.00000,30 font ":Italic"
set polar
set grid polar 30.0000 lw 1.5
plot cos(4*t) lt 3 lw 2
Thank you in advance!
I guess there is no "intended" way to limit the maximum angle in a polar plot.
So, there is a simpler (but ugly) workaround, which simply covers the unwanted part by a filled polygon.
Note: There will be an issue if your rmax is not an integer multiple of rtic 0.2, i.e. a plot with rmax=1.05 will not look as desired. Therefore, as a workaround an extra rtic at rmax is added.
Script:
### plot only part of polar plot
reset session
rmax = 1.05
amax = 60
set polar
set rrange [0:rmax]
set rtics 0.2 scale 0.5
set rtics add ('' rmax)
set grid r polar 10 lt black lw .3
set trange [0:2*pi]
set ttics 0,10 format "%g°" font ":Italic" scale 0.5,0.25 offset -1,0
set mttics 2
set xlabel "r-label"
set xrange [0:rmax]
unset xtics
set yrange [0:rmax]
unset ytics
set size square
set border 4096
set lmargin 0
set tmargin 0
unset title
unset key
set samples 300
set obj 1 polygon from graph 0,0 to first rmax*cos(pi/180*amax),rmax*sin(pi/180*amax) \
to first rmax*cos(pi/180*amax), screen 1.0 \
to first 0, screen 1 to screen 0,1 to screen 0,0 to graph 0,0 \
fc rgb 0xffffff fs solid 1.0 front
set arrow 1 from graph 0,0 to first rmax*cos(pi/180*amax),rmax*sin(pi/180*amax) lc "black" nohead front
plot cos(4*t) lt 3 lw 2
### end of script
Result:

How to move and manage overlapping of x ticks with axis in Gnuplot

I am trying to plot an inlet graph which is shown in Figure. Being an inlet graph it is needed to show x tics and y ticks of relatively big sizes for clear visibility. But when I increase the fonts as,
set xtics font ", 40"
tics overlaps with axis. I increased the plot size set term png size 1000, 1000 but still the issue persists. Kindly suggest if there is a way to move the tics below or to a desired position in graph.
Edit:
The gnuplot script looks like this,
set term png size 1000, 1000
set output "b_vs_N.png"
set style fill solid
set style circle radius 0.001
FIT_LIMIT=1.e-14
set yrange [0.15:0.25]
set style fill solid
set style circle radius 0.001
set xtics 10
set ytics 0.03
set border 15 back lw 6
set xtics font ", 40"
set ytics font ", 22"
set ylabel "b" enhanced font "1 {,40}"
set xlabel "N_i" font "1 {,40}"
set lmargin 12
set bmargin 4
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
AA(x)=a+b*x+c*x**2
fit AA(x) "data.txt" using 1:2 via c, b, a
plot "data.txt" using 1:2 lt 1 pt 11 ps 2.0 lc rgb "black" notitle, AA(x) w lines lw 2 lc rgb "sienna1" notitle
Your example is uncomplete without code and therefore difficult to reproduce. Please check help xtics. There is the option offset.
Maybe the following example helps to solve your issue.
In the example below no special offset seems to be necessary, i.e. offset 0,0, but you can shift and adjust the labels in x and y direction.
Code:
### tic label offset
reset session
set multiplot
plot sin(x)/x
set origin 0.07, 0.6
set size 0.3,0.3
set xrange [0:10]
set xtics 5 out font ",20" offset 0,0
plot x**2
unset multiplot
### end of code
Result:

plotting two different types of histogram plots in gnuplot on top of each other

I am working with a histogram in gnuplot and I want to put one of the histogram bars behind the other results. I would like the reference bar (Mörk spennubjögunar > 200 kV) to behind the other histogram bars. I have done this in excel before using different y-axis, is there a nice way to do this in gnuplot?
This is the code I am currently working with.
set terminal pngcairo transparent nocrop enhanced size 3200,2400 font "arial,40"
set output "Harmonic_currents_BRE.png"
set key right
set datafile separator ";"
set style line 12 lc rgb '#808080' lt 0 lw 1
set style line 13 lt 0 lw 3
set grid back ls 12
set xrange [-1:20]
set yrange [0:8]
set style data histogram
set style histogram cluster gap 1
set style fill solid border 0
set border lw 2
set boxwidth 0.7
set ylabel "Hlutfall af nafnspennu [%]"
set xlabel "Tíðni [pu 50 Hz base]"
plot "case0.csv" using 2:xticlabels(1) title 'Tilfelli 0',\
"case1.csv" using 2:xticlabels(1) title 'Tilfelli 1',\
"case2.csv" using 2:xticlabels(1) title 'Tilfelli 2',\
"case3.csv" using 2:xticlabels(1) title 'Tilfelli 3',\
"ref.csv" using 2:xticlabels(1) title 'Mörk spennubjögunar > 200 kV'
unset output
unset zeroaxis
unset terminal
I think, the best way is to first plot the reference with boxes with a fixed boxwidth (I used 0.9), and then the clustered histograms:
set style data histogram
set style histogram cluster gap 1
set style fill solid noborder
set boxwidth 0.7
plot "ref.csv" using 0:2:(0.9):xtic(1) with boxes title 'Mörk spennubjögunar > 200 kV',\
for [i=0:3] sprintf("case%d.csv", i) u 2 title sprintf('Tilfelli %d), i)

how to change gnuplot's graph size

I am trying to plot a graph with increased font size in gnuplot. A typical example is:
p sin(x) w l lw 5
set border lw 4
set tics font "Halvetica Bold,20"
So, I am trying to have:
adjust plot size without changing the canvas size to accommodate x/y label and tics
to adjust space between tics and label
How can I achieve this?
Kindly help.
The margins and the label positions depend on the total font size. You can specify this as part of the set terminal command.
The following script gives good margins and label positions:
set terminal wxt font ",20"
set border lw 4
plot sin(x) lw 5
For your example, you could adjust the margins with set lmargin ... and similar commands, and adjust the tic offset with set xtics offset ...:
set terminal wxt
set border lw 4
set tics font "Halvetica Bold,20"
set bmargin 3
set lmargin 10
set xtic offset 0,-1
set ytics offset -0.5,0
plot sin(x) lw 5

Gnuplot change color of bars in histogram

is it possible to change the color of bars in a Gnuplot script dynamically?
I have the following script
reset
fontsize = 12
set term postscript enhanced eps fontsize
set output "bargraph_speedup.eps"
set style fill solid 1.00 border 0
set style histogram
set style data histogram
set xtics rotate by -45
set grid ytics linestyle 1
set xlabel "Benchmarks" font "bold"
set ylabel "Relative execution time vs. reference implementation" font "bold"
set datafile separator ","
plot 'bm_speedup.dat' using 2:xtic(1) ti "Speedup" linecolor rgb "#00FF00"
which generates this plot:
Is it possible to make the color of the bars which are below zero red?
Thanks,
Sven
You can mimic this behavior using the boxes style:
My test data:
zip 2
baz 2
bar -1
cat 4
foo -3
And then plotting with gnuplot:
set style line 1 lt 1 lc rgb "green"
set style line 2 lt 1 lc rgb "red"
set style fill solid
plot 'test.dat' u (column(0)):2:(0.5):($2>0?1:2):xtic(1) w boxes lc variable
# #xval:ydata:boxwidth:color_index:xtic_labels
You could split your data file into two parts, positive values and negative, and plot them separately:
plot 'bm_speedup_pos.dat' using 2:xtic(1) ti "Faster" linecolor rgb "#00FF00", \
'bm_speedup_neg.dat' using 2:xtic(1) ti "Slower" linecolor rgb "#FF0000"
Or, if you only need to generate a few graphs, a few times, a common technique is to generate the raw graph in gnuplot, then post-process it in an image editor to adjust the colors. If you go that route, I suggest having gnuplot generate the graph in SVG format, which will give you much better looking graphs than any of the bitmap formats.
Doesn't seem like histogram lets you do it. May be like this:
set boxwidth 0.3
f(v)=v<0?1:2
plot 'bm_speedup.dat' using 0:2:(f($2)):xticlabels(1) with boxes ti "Speedup" lc variable
Actually you can also use linecolor rgb variable and give the color like this:
plot 'bm_speedup.dat' using 2:xtic(1):($2 >= 0 ? 0x00FF00 : 0xFF0000) ti Speedup lc rgb variable

Resources