The last couple of hours I've been trying to produce an acceptable-looking plot of a 3D-Object. Now i'm totally stuck at somehow making Gnuplot draw the borders in respect to my 3D-object in a right way. The code I use is this:
reset
set term pngcairo enhanced size 800,600
set output "plot.png"
set grid xtics ytics ls 3 lw 1 lc rgb 'gray'
set xzeroaxis
set yzeroaxis
set samples 30,30
set isosamples 30,30
set style line 100 lt 5 lw 0.5 lc black
set palette gray
set cbrange [-1:1]
unset colorbox
set pm3d depthorder hidden3d implicit
set pm3d lighting primary 0.50 specular 0.6
set parametric
set urange [0:2*pi]
set vrange [0:2*pi]
set xrange [-3.1:3.1]
set yrange [-3.1:3.1]
set zrange [-1.1:1.1]
set xyplane at -1
set view 121,115
set xtics offset first 0,0, -0.1
set ytics offset first 0,0, -0.1
set ytics -2,1,2
set xtics -2,1,2
unset border
set border 4095 front lt black linewidth 2.000 dashtype solid
splot (2+cos(u))*cos(v),(2+cos(u))*sin(v),1*sin(v) lc rgb '#666666'
set output
If you plot that code it results in an image like this:
3D-Object Plot
As you can see the layering of Borders/Axes and Graph is somehow messed up. I spent some time playing around with different terminal types, or set border back / front / behind, or basically all the other options, but i could not succeed in making Gnuplot draw this the right way, which means, the borders surround my Object.
The only compromise solution i could find, is, if i choose certain different view-points Gnuplot gets it all right. But for the one i want the drawing does not work..
I would be very happy about any suggestions or hints!
Related
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:
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:
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.1
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
plot sin(x) lc 0
This code displays the problem - different positionning of x/y labels by splot, plot.
Although you have the margins identical for both plots for some reason (which I don't know) the labels are not at identical positions. However, since the label values are identical anyway, no need for trying to plot the second labels on top of the first ones. Simply skip all labels and tics of the second plot.
Code:
### remove shifted tics in multiplot
reset session
set xrange [-2:2]
set yrange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set lmargin screen 0.1
set rmargin screen 0.9
set tmargin screen 0.9
set bmargin screen 0.15
set multiplot
set pm3d map
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2
unset pm3d
unset xlabel
unset ylabel
unset xtics
unset ytics
plot sin(x) lc 0
unset multiplot
### end of code
Result:
It is quite possible that you can create your composite plot entirely with splot and therefore do not need to use multiplot, bypassing the whole issue. I realize that the example you give may be over-simplified but as it stands the plot can be created by
set xrange [-2:2]
set yrange [-2:2]
set trange [-2:2]
set xlabel 'X'
set ylabel 'Y'
set samples 300
set isosamples 300
set view map
set pm3d at b
set palette grey
unset colorbox
splot x**2+y**2 < 1 ? 0:0.2 with pm3d, \
'+' using 1:(sin($1)):(0) with lines lc "blue" lw 3
With gnuplot 5.2.8, the figure can be created with just one plot command:
pl [-2:2][-2:2] sample [0:2*pi] "+" us (cos(x)):(sin(x)) with filledcurve, sin(x)
Thus splot and multiplot are not needed here.
sample is needed to redefine the parameter range (only in case of first plot argument).
A documentation is here: https://github.com/gnuplot/gnuplot/blob/4a7a11e6b528ea362c943cf632fd21a518b15c54/docs/gnuplot.doc#L7856
PS: As you see it also works without $1 for your cairolatex terminal.
I'm trying to add some guiding lines over a pm3d map using Gnuplot.
Below is the code I use to plot pm3d map (my pm3d map).
set terminal post eps enhanced color solid "Helvetica" 16
set encoding iso_8859_1
set hidden3d
set pm3d map
set view map
unset surface
set size square
splot "map.ene" with image
set xlabel "RC1 ({\305})"
set ylabel "RC2 ({\305})"
set cblabel "{/Symbol D}G (kcal/mol)" offset 1,0,0
set xrange ["1":"11"]
set yrange ["5.5":"9.5"]
set cbrange ["-3.1":"0.0"]
set xtics 1
set ytics 1
set cbtics 1
set mxtics 2
set mytics 5
unset key
set palette defined (-3.1 "red", -2.5 "yellow", -1.5 "green", -0.5 "blue", 0 "white")
unset colorbox
set output "map.eps"
replot
map.ene is in the format below:
1.000 5.500 0.00000 i
Now I want to add a vertical line (x=5.5) over the pm3d figure. I searched old posts and found similar questions already been asked by others. Seems there are two possible solutions:
1) prepare a separate data file for the line (x.dat, 5.5,y,0.0) then use command below to plot.
splot "map.ene" with pm3d, "x.dat" using 1:2:(0.0) with points linecolor rgb "black"
2) use "multiplot" facility in Gnuplot.
I tried both, neither worked. I've been playing this for a while but sill not sure how I should modify my original pm3d code to add guiding lines.
you can draw lines in gnuplot:
set arrow from first 5.5, graph 0 to first 5.5, graph 1 nohead
type help coordinates to better tune the above command.
Can anyone help me or give me some tips how to create histogram and curve on same plot? When I try to do it, gnuplot is plotting a histogram or a curve, but not both of them.
This is code I used:
#!/usr/bin/gnuplot -persist
f(x)=99*0.03*(1/(0.062*sqrt(2*pi)))*exp(-((x-1.28)**2)/(2*(0.062**2)))
set xrange [1:1.43]
set yrange [0:25] noreverse nowriteback
plot f(x)
set boxwidth 2 absolute
set style fill solid 1.00 border lt -1
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror offset character 0, 0, 0
set xtics norangelimit
set xtics ()
i = 23
replot 'histogram1.txt' using 2:xtic(1)
set output 'histogram1.png' `
Not having the data set you are plotting, I must guess how the final result should look like...
When plotting histograms, gnuplot implicitely places the boxes at integer x-values, starting at 0, and with custom xtics, when having using 2:xtic(1). You set the xrange to [1:1.43] to plot your function properly. Probably you want to plot with boxes to get it right.
Try:
f(x)=99*0.03*(1/(0.062*sqrt(2*pi)))*exp(-((x-1.28)**2)/(2*(0.062**2)))
set xrange [1:1.43]
set yrange [0:25]
set boxwidth 0.8 relative
set style fill solid 1.00 border lt -1
set datafile missing '-'
plot f(x), 'histogram1.txt' using 1:2 with boxes