Adjusting the position of countour base plane in gnuplot - gnuplot

I am trying to use gnuplot to plot the graphene band structure as both surfaces and a countour plot at the base, set with set contour base, but I can't get rid of some axis lines and the plane where the contour is drawn is too far away from the surfaces when I place them in the adequate viewing angle.
Here is the code to plot the graph
# Setting ranges and function parameters
set xrange [-.55:.55]
set yrange [-1:1]
t=-3.033 s=0.129 a=1.43 * sqrt(3)
# Auxiliary functions
kx(x,y) = (2*pi/a) * (cos(pi/6)*x + sin(pi/6)*y) ky(x,y) = (2*pi/a) * (cos(pi/6)*x - sin(pi/6)*y)
w(x,y) = sqrt(1+4*cos(0.5*sqrt(3)*kx(x,y)*a)*cos(0.5*a*ky(x,y)) + 4*(cos(0.5*ky(x,y)*a))**2)
#functions to be plotted
e(x,y) = (t*w(x,y))/(1+s*w(x,y))
e_estrela(x,y) = (-t*w(x,y))/(1-s*w(x,y))
# Setting up 3D plot appearance
set hidden3d
set contour base set cntrparam levels discrete 0,0.5,1,2,4,8
set view 75, 31, 0.601098, 1.4385
set isosamples 60
# Removing unwanted stuff
unset xtics
unset ytics
unset ztics
unset key
splot e_estrela(x,y), e(x,y)
And the output I get (with the pngcairo terminal, but that's not relevant, I guess) is:
Is it possible to draw the contour base plane closer to the surfaces? And how about removing those vertical black lines?
For the first part, I tried playing wioth set zrange with no success. The base plane seems to be drawn a certain z-distance below the lowest z-range limit everytime.
Ideas? Thanks in advance!

To adjust the distance between your data and the xy-plane use the option
set xyplane relative <value>
where <value> gives you the distance between the xy-plane and the minimal z-value in relative fraction of the hight of your plot. So <value>=0 sets the distance to zero, <value>=0.5 to half the hight.
To control the border use set border where each border line is represented by bits. Please refers to the documentation for more details. In your case I would suggest:
set border 127+256+512 # or set border 1023-128
set grid #forces borders from xy-plane to plot

Related

gnuplot: viewing angle dependent colors with 3D circles in GIF terminal

With gnuplot 5.4 (Win7), I tried to animate circles in 3D, basically the animated version of this.
The test data $Data contains random x,y,z coordinates, random sizes and random colors from 0x0000000 to 0xffffff. When the animated GIF is created, the circles are changing the color depending on the viewing angle.
As far as I know, GIF is limited to 256 colors, so it is clear that not all colors from 0x0000000 to 0xffffff can be displayed.
I expected gnuplot to take somehow the nearest color and stick with it.
However, I didn't expect at all that the color of the circles would change depending on the angle.
Why is this? How to work around this?
Code:
### animated plot with circles in 3D (only for gnuplot >=5.4)
reset session
set term gif size 400,400 animate delay 30 optimize
set output "WithCircles3D.gif"
# create some test data
set print $Data
do for [i=1:100] {
print sprintf("%g %g %g %g %g", rand(0), rand(0), rand(0), rand(0)*0.02+0.02, int(rand(0)*0xffffff))
}
set print
set view equal xyz
set xyplane at 0
set border 4095
set xtics 0.2
set ytics 0.2
set ztics 0.2
set style fill solid 1.0
do for [a=5:360:10] {
set view 60,a,1.25
splot $Data u 1:2:3:4:5 w circles lc rgb var notitle
}
set output
### end of code
Result:
Result 2: (different random set when exporting single PNG frames with term pngcairo and put them together as animated GIF with some other software.)
I think the work-around is to not use the "optimize" option. It relies on upstream support (in libgd) that has been unreliable if not outright broken for years now. Probably we should deprecate the gnuplot option or remove it altogether.
The example you show works correctly if you remove that keyword, right?

Gnuplot countours with discrete data points and dgrid3d

I am trying to plot some experimental data points (defined by x, y, and z) and and some "iso-z" lines. To plot contour lines, the data need to be in a grid format. I tried to follow proposed elsewhere, where by means of dgrid3d the experimental, nongrid data, are converted by interpolation into grid points, and use these new data points to draw the contour lines.
The script looks as follows:
reset
set term pdf color enhanced font 'Arial, 18' size 13.5cm,9.2cm
set out 'phasediag.pdf'
#Here I convert the data points, stored in 1f.dat into a grid format.
set table '1f-grid.dat'
set dgrid3d 50,50
splot '1f.dat' u 3:4:2
unset table
#Here I would like to draw the countour lines, to be used after in the plot.
set contour base
set cntrparam level auto 5
unset surface
set table 'cont.dat'
splot '1f-grid.dat'
unset table
# Load the palette color definition.
load 'parula.pal'
set logscale cb
set cbrange[1e5:1e9]
set format cb '10^{%1.1T}'
set cblabel 'Mw / g mol^{-1}' offset 2.5,0
set format x '%1.1f'
set format y '%1.1f'
set label '1{/Symbol F}' at 0.4,6.3
set label '2{/Symbol F}' at 2.15,3
plot[0:2.7][2.5:7] '1f.dat' u 3:4:2 with points pt 5 palette, '2f.dat' u 3:2 with points pt 7 lc rgb "black"
set out
Unfortunately, I get the following error when I try to draw the contour lines in the cont.dat file:
Warning: Cannot contour non grid data. Please use "set dgrid3d".
The error surprises me a bit, as the data produced in the first where produced using dgrid3d and are in grid format.
By commentig out the section in which the contour lines should have been drown, I get the following output:
I would simply draw some lines at constant z-values. Any hint for that?
Thanks in advance,
Leo

GNUPLOT - Add a 2D curve in a 3D Contour plot

I already have a nice 3D plot, with only contour projection from a data file. And I want to add a simple function on it. How can I do this?
here the code:
set autoscale
set terminal png
set contour
set output 'Corrugation_uwtp_HorizontalWind.png'
set pm3d map
set samples 50; set isosamples 50
unset key
set palette rgbformulae 33,13,10
set xlabel "Horizontal distance"
set ylabel "Vertical height"
splot "CORRUGATION_C_UWTP.dat" u 1:2:3
and I want to add following functin:
h(x)=sin(x)
Thank you for your help
Not possible directly, you have to make it in three steps, as 2D plot:
1st plot the contour to a table:
set contour; unset surface
set table $datatable
splot dataf
unset table
2nd plot the contours and your function
plot for [i=0:5] $datatable index i, f(x)
3rd plot the datafile as a coloured surface
replot dataf with image
If you use a gnuplot version prior to 5.0, you have to plot the table output to a temporary file instead of $tablename.

Non-linear secondary xlabel

I want to plot a function/dataset, where the secondary x-axis is a function of the primary x-axis, e.g. 1/x (non-linear). The reason for this is that they are both meaningful parameters. I can set the range correctly by using my "function", however, values in between are different. The following figure shows what is wrong:
What is wrong here, is that the x2-axis get linearly ticced (is that proper English?). Example: the tic opposite to 1.6 is now 0.7, but should be 0.625 for this case.
Script to reproduce this:
xmin=1.
xmax=2.
set xlabel "x"
set xrange [xmin:xmax]
set x2tics
set x2label "1/x"
set x2range [1/xmin:1/xmax]
plot x
Is a fancy general way to change the axis-scaling/labeling, other than logarithmic?
You can use a do for approach to loop through a manual label setting (set x2tics add). Here's the edited minimal example you provided (see comments in the script for explanations):
xmin=1.
xmax=2.
inc=0.2 # for more control over the tics
f(x)=1./x # Function that defines the secondary axis
fplot(x)=x # Function that is plot
set xlabel "x"
set xrange [xmin:xmax]
set xtics xmin,inc,xmax # specify the actual location for xtics, too
ntics = (xmax-xmin)/inc + 1 # calculate the number of tics
inc2 = (f(xmin)-f(xmax))/(ntics-1) # calculate increment for x2tics
fmin=f(xmin); fmax=f(xmax)
set x2tics fmin,-1*inc2,fmax # set x2tics, labels will be rewritten
# the following loops through the number of tics
# the <set x2tics add ("x2" x2)> command will be repeated
# use arithmetic to calculate the values and the locations
# you need <sprintf> to convert the tic label number into a string
do for [i=1:ntics+1] {
xtic=xmin+(i-1)*inc
x2ticpos=f(xmin)-(i-1)*inc2
set x2tics add (sprintf("%.3g",f(xtic)) x2ticpos)
}
set x2range [f(xmin):f(xmax)]
set yrange[fplot(xmin):fplot(xmax)] # you should also specify the yrange, to avoid surprises
plot fplot(x)
And the plot you'll get is this:

gnuplot: how to put two figures side by side

I'm trying to put two figures side by side using gnuplot with multiplot.
I want the resulting image to be rectangular so I use set size 2, 1. I also set the set multiplot layout 1, 2 option. However, the resulting image only uses the left part of the available space. Any help will be appreciated.
Thanks
Ahmet
Here is the resulting image
http://tinypic.com/r/33mlz04/6
And below is the gnuplot commands I'm using.
set terminal postscript eps color enhanced
set output 'figure.eps';
set size 2,1;
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
Although I'm not very sure, with some trial and error I have solved it
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1,0.5;
set multiplot layout 1, 2 ;
set title "Figure 1";
set size 0.5,0.5;
plot "data/data1.txt"
set title "Figure 1";
set size 0.5,0.5;
plot "data/data2.txt"
unset multiplot
Try something like:
set terminal postscript eps color enhanced size 10,5
set output 'figure.eps';
set multiplot layout 1, 2 ;
set title "Figure 1";
plot "data1.txt"
set title "Figure 1";
plot "data2.txt"
unset multiplot
When you set the size on the terminal specification line, that determines the actual size of the plot canvas (in inches in this case). When you use set size on a separate line, that sets the size of the plot in relative units of the canvas size. This is different in older versions of gnuplot. For perhaps a better explanation, try help set size in gnuplot.
For even more control over the size/position of the plot, you can use set origin in conjuction with set size to change the placement and size of each plot. Finally, the most control can be achieved with set lmargin at <place> (and set rmargin ...) and so-on for tmargin and bmargin where the "lrtb" stand for left, right, top and bottom respectively.
So, to get a plot to fill all of the available space (left to right), you could:
set multiplot
set lmargin at 0
set rmargin at .5
plot sin(x)
set lmargin at .5
set rmargin at 1
plot cos(x)
unset multiplot
However, this is (usually) overkill. Usually gnuplot tries to make the margins big enough for your labels and such, but setting the margin explicitly disables that. I would suggest you go with the solution by andyras.
if you are having problems using this method for more than 2 figures add 'set origin 0,0' after 'set size 0.5,0.5'.
For example, for three figures :
set terminal postscript eps color enhanced
set output 'eps/image.eps';
set size 1.5,0.5;
set multiplot layout 1, 3 ;
set title "Figure 1";
set size 0.5,0.5;
set origin 0,0
plot "data/data1.txt"
set title "Figure 2";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
set title "Figure 3";
set size 0.5,0.5;
set origin 0,0
plot "data/data3.txt"
unset multiplot

Resources