Difference between drawing using Gnuplot and OriginLab - gnuplot

I have two data files, qebands.agr and ex1_band.dat. When I plot them using OriginLab I got directly this figure:
On the other hand, someone used Gnuplot with the following script:
set xtics nomirr
set x2tics
set xrange [*:*] noextend
set x2range [*:*] noextend
plot 'qebands.agr' w l, 'ex1_band.dat' axes x2y1 w l
and get:
I haven't used Gnuplot before.
Could anyone tell me why the two figures are different? i.e., why the scale the x-axis is different in both figures?

Depending on which image is the desired one...
Remove axes x2y1 in the second part of the gnuplot command and you will get a similar plot as the Origin one.
You are explicitly specifying that 'ex1_band.dat' is plotted to axes x2y1 (x2 = top x-axis, y1 = left y-axis).
Per default, gnuplot autoscales both x-axes independently, unless you link them (check help link).
Origin is plotting both files relative to x1y1 axes.

Related

gnuplot multiplot layout not being overridden by set origin, ways to position subplots

This question is to some part identical to what has already been asked here. But the referenced question never received the answer to the point whether the issue presented here is a bug or documentation confusion.
Documentation states with respect to the layout option of multiplot:
With the layout option you can generate simple multiplots without
having to give the set size and set origin commands before each plot:
Those are generated automatically, but can be overridden at any time.
My understanding of that text is that layout sets origin and size and at any time, i can change those specifications. Then this should work:
set xrange [0:10]
set multiplot layout 3,1 margins 0.1,0.95,0.12,0.95 spacing 0,0
unset key
plot cos(x) axes x1y1 w l ls 3 notitle
plot sin(x) axes x1y1 w l ls 3 notitle
set key bottom center out horizontal
plot sin(x) axes x1y1 w l ls 3 notitle
set origin 0.3,0.5
set size 0.2,0.1
set xrange [1:2]
plot cos(x) axes x1y1 w l ls 3 notitle
unset multiplot
But it does not. gnuplot completely ignores set size and set origin commands. What it should do is to plot 3 plots under each other and then create an inset at screen position (0.3,0.5) of size relative to canvas (0.2,0.1).
My questions are:
Is this a bug that should be reported or is this poorly formulated documentation issue (that layout can be overridden by set position and set size)?
multiplot offers two ways to position the sub-plots, set origin + set size and set *margin where * stands for one of b,t,l,r. Can someone provide a deeper explanation when one should use which? (For me it feels the proper way that was meant to do it is set origin and margins just became a dirty trick that works but was not meant for that)
What would be the cleanest way to produce the plot that I am looking for that would be easily reproducible (for any other problem, not just 3 plots but any plots and without some tedious calculations of positions)?
Is there a way to print the settings of origin, size, margins and any other relevant settings that are automatically calculated (and used) when the layout option is specified?
My guess would be that it is a bit unclear documentation.
It's a matter of taste and convenience and depends on your situation. Setting origin and size is setting the place for the (sub-)"canvas". This (sub-)"canvas" still can have some individual b,t,l,r margins. Note, margins are the space between graph border and canvas-border.
Apparently, the margins which you are setting in the multiplot layout are kept for your extra plot.
So, apparently you have to reset them, e.g. set margins 0,0,0,0. And then you are probably getting your intended plot.
I am not aware that you can extract the automatically calculated values for margins. There are no such values
listed in show var GPVAL.
Code:
### multiplot layout with manual origin and size
reset session
set xrange [0:10]
unset key
set ytics 0.5
set multiplot layout 3,1 margins 0.1,0.95,0.12,0.95 spacing 0,0
plot cos(x) axes x1y1 w l ls 3 notitle
plot sin(x) axes x1y1 w l ls 3 notitle
set key bottom center out horizontal
plot sin(x) axes x1y1 w l ls 3 notitle
set margins 0,0,0,0
set origin 0.3,0.5
set size 0.2,0.1
set xrange [1:2]
plot cos(x) axes x1y1 w l ls 3 notitle
unset multiplot
### end of code
Result:

Gnuplot: How to continue a pm3d plot to the outside of the set range?

I have a problem with plotting my data points with pm3d in gnuplot. In my data file, the points (2-dim domain) are not rectangular aligned, but parabolic as shown in this figure, where the data points are not aligned exactly above each other. My goal is to create a heatmap with pm3d for a specific xrange where the heatmap is continued to the borders of the selected xrange.
What I did:
Plotted the data set with pm3d using the following minimal code example:
set terminal qt
set xrange [-0.25:1.00]
set view map
splot "data.txt" u 1:2:3 with pm3d
What I got:
A heatmap of my data file, but with ugly corners at the border points at where I cut my x-domain, because the border points are not aligned "above" each other.
What I expected:
A heatmap where the "heat" values are continued to the real border of the domain as it is the case for a simple "with lines" plot, shown in this figure.
My attempts so far to achieve what I expected:
I tried several pm3d options, including the option clip1in, which only requires 1 clip of a "heat rectangle" to be inside the domain, but the result was that the corners are no laying outside of the domain, which doesn't solve the problem unfortunately.
Additional information:
OS: Ubuntu 20.04
$ gnuplot -V
gnuplot 5.2 patchlevel 8
If anybody knows how I achieve what I'm trying to do, it would be nice to share that knowledge!
Cheers!
Gnuplot 5.4 does offer this sort of smooth clipping on the z coordinate, but unfortunately that doesn't help because you want clipping on x in this case.
Here is an example of performing x clipping by manual intervention.
The complicated expression for the x coordinate is just to generate points
with a non-orthogonal grid.
xclip(x) = x > 6. ? 6. : x # clip x to maximum value of 6.
f(x,y) = sin(sqrt(x*x + y*y)) # some function to plot
set sample 21; set isosample 21
set view map
set xrange [-6 : 6]
unset key
set multiplot layout 1,2
set title "No clipping"
splot '++' using ($1+$2*$2/10.) :($2):(f($1,$2)) with pm3d
set title "Manual clipping at x=6"
splot '++' using (xclip($1+$2*$2/10.)):($2):(f($1,$2)) with pm3d
unset multiplot

Is there a bug in Gnuplot 5.2 (patch 5) with `multiplot` command?

I'm running Gnuplot version 5.2, patch level 5, and I am getting unexpected behavior from the multiplot command. In efforts to produce two plots, one smaller and superimposed on the larger one, I am using the multiplot environment in the following way:
reset
set multiplot
set origin 0,0
set size 1,1
plot "first_file.dat"
set origin 5,5
set size 0.5,0.5
plot "second_file.dat"
unset multiplot
When I first run set multiplot an empty canvas shows up that I close. Then, when I enter unset multiplot nothing happens. From following instructions online it seems like the unset command is supposed to produce the plot, but it doesn't. Am I doing something wrong, or is there a potential bug with this version?
Why do you close the empty canvas? You won't see anything until you plot your data. The following code gives two superimposed plots. However, the set origin coordinates are relative to the screen (ranging from 0.0,0.0 to 1.0,1.0). If you want to place the second graph relative to some coordinates of the first graph, this probably would require some calculations.
reset session
set colorsequence classic
set multiplot # will show an emtpy canvas
plot sin(x) lt 1 # will show the first plot
set origin 0.1, 0.45 # origin coordinates are relative to the screen
# not to the coordinates of the first plot
set size 0.5,0.5
plot cos(x) lt 2 # will show the second plot on top of the first plot
unset multiplot
Result (wxt terminal):

Setting gnuplot yrange to fit one curve only

I have a Gnuplot script that draws 2 curves from a data file. If I don't specify yrange, Gnuplot sets it so that all the points of both curves fit in the figure. In my case I would like Gnuplot to only care about one of the curve (it does not matter if the other goes out of range, since I'm interested only in the parts of the figure where the second curve gets close to the first one).
I could find out the minimum and maximum values taken by the first curve, and manually set yrange to those values, but my Gnuplot script is intended to run automatically on many data files, producing many figures for which yrange is not the same, so I'm looking for a way to do that automatically.
Thanks
There are different options, depending on the used gnuplot version:
Version 5.0:
The data file which should be excluded from the autoscaling gets a noautoscale parameter:
plot 'first.dat' using 1:2, 'second.dat' using 1:2 noautoscale
Version >= 4.6:
Use the stats command to get the minimum and maximum value of the relavant data file:
stats 'first.dat' using 1:2
set yrange [STATS_min_y:STATS_max_y]
plot 'first.dat' using 1:2, 'second.dat' using 1:2
At least since 4.0:
Use set yrange [] writeback to save the autoscaled ranges from a plot command and set yrange restore to use them for a later plot:
set terminal push
set terminal unknown
set yrange [] writeback
plot 'first.dat' using 1:2
set yrange restore
set terminal pop
plot 'first.dat' using 1:2, 'second.dat' using 1:2

Smoothing out contourplot in Gnuplot?

I am trying to plot a simple contour plot (in gnuplot) for the Himmelblau's function using the following code :
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set table 'cont.dat'
splot f(x,y)
unset table
reset
set xrange [-5:5]
set yrange [-5:5]
unset key
p './cont.dat' w l lt -1
I get the following plot result:
There are a few problems with the plot which I wish to eliminate:
It shows some horizontal lines in the plot, I don't know why. How can I remove the horizontal lines?
The contour lines are not too smooth. How can I improve there smoothness?
I feel that both the above problems are connected but can't figure out how. Can you please help me understand and hopefully eliminate the problems?
EDIT 1 : I found the answer to question-2, i.e. improving smoothness. I could do it by increasing the isosample. But I still get a lot of horizontal lines as shown in figure below.
But how to remove these horizontal lines? I just want the contour lines for the levels specified.
Here is how you can plot only the contour lines: You must use unset surface, which plots only the contour lines, and view the plot from above with set view map. See also the 2D contour projection plot from the gnuplot demos.
Smoothing can be achieved with set isosamples, but in some way also using e.g. set cntrparam bspline and similar.
So your script becomes:
f(x,y)=(((x**2)+(y)-11)**2)+(((x)+(y**2)-7)**2)
set xrange [-5:5]
set yrange [-5:5]
set contour base
set cntrparam level discrete 13.59085,25,50,100,150,300,500,1000
set isosamples 250
unset surface
set view map
set key out
splot f(x,y)
With the result (using 4.6.3):
I was able to solve both the problems. The solution to Problem-2 I already shared in the edit-1 of question.
For Problem-1, i.e. removing the IsoLines from the contour plot, I should have left the initial blocks of data int he cont.dat files which contain the data for the isolines. Instead, I should have plotted from the Data Block 250 onwards (first 250 blocks of data were from IsoLines because of set isosample 250,250 command).

Resources