Gnuplot. tics on axis and border. Number only on border - gnuplot

working on my thesis here.
I've been trying to plot with tics on the border and the zero axes. I just want to have numbers on the border.
The result expected should be as if the 2 images attached were combined.
Is there any way to do this?
Code First image:
set xtics axis
set ytics axis
set format x ""
set format y ""
set xzeroaxis linetype -1
set yzeroaxis linetype -1
set tics in scale 1
set mxtics 2
set mytics 2
set xtics mirror
set ytics mirror
Code Second image:
set xtics border
set ytics border
set format x "% g"
set format y "% g"
unset xzeroaxis
unset yzeroaxis
set tics in scale 2.5
set mxtics 5
set mytics 2
set xtics mirror
set ytics mirror
Thanks!!!

As I understand the documentation (check help xtics) you can have the tics either at the axis or at the border but not both.
set xtics {axis | border} {{no}mirror} ...
A quick and dirty solution would be using multiplot. You need to fix the margins to get the plots exactly on top of each other. Check the following example as starting point, maybe there are smarter solutions.
Code:
### having tics at the border AND axis
reset session
set xrange [-0.4:0.4]
set xtics 0.1 border
set mxtics 5
set yrange [-1:1]
set ytics 0.2 border
set mytics 2
set xzeroaxis linetype -1
set yzeroaxis linetype -1
set tics in scale 1
set margins 10,10,3,3 # <left>, <right>, <bottom>, <top>
set key noautotitle
set multiplot
plot sin(12*x)
set xtics axis
set format x ''
set ytics axis
set format y ''
plot NaN # dummy plot
unset multiplot
### end of code
Result:

Related

I'm trying to use multiplot to combine plot and splot but x,y labels seem to be shifted

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.

Gnuplot - Show different tick color at 0

I want to display different tick color at 0.
For eg, the image below I want to set tick color at 0 in y axis to blue. Can it possible? Thanks.
I am not aware of a direct Gnuplot feature that would allow to do this, nevertheless one might use some workaround.
For example, one could unset the tic at position zero and place there a custom label instead:
set terminal pngcairo enhanced font ",14"
set output 'fig.png'
set multiplot
xMin = 0
xMax = 2*pi
set xr [xMin:xMax]
set yr [-1:1]
set xtics out nomirror
set ytics out nomirror
set ytics add ("" 0)
set label "0" at xMin,0 offset char -1.5,0 right textcolor rgb "blue"
plot sin(x) w l t 'sin(x)'
Alternatively, one could use a technique based on multiplot, where the strategy is basically first to plot the function/data of interest without the tic at position zero and then overlay this with a plot which is empty but for the customized tic at position zero:
set terminal pngcairo enhanced font ",14"
set output 'fig.png'
set xr [0:2*pi]
set yr [-1:1]
set xtics out nomirror
set ytics out nomirror
set ytics add ("" 0)
plot sin(x) w l t 'sin(x)'
set lmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_XMIN / (1.*GPVAL_TERM_XSIZE)
set rmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_XMAX / (1.*GPVAL_TERM_XSIZE)
set bmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_YMIN / (1.*GPVAL_TERM_YSIZE)
set tmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_YMAX / (1.*GPVAL_TERM_YSIZE)
unset border
unset key
unset xtics
unset ytics
set ytics ("0" 0) out nomirror textcolor rgb 'blue'
plot 1/0
Both approaches result in a nearly identical plot:

How can I get rid of the ticmarks on the x2 & y2 axes of a gnuplot?

Here is a picture of the problem I am facing: Gnuplot
Additional unlabelled tics appear in my gnuplot on the x2&y2 axis. This is how I have defined the plot:
set grid lt -1 lw 0.709
set border 3 lt -1 lw 0.992
set size ratio 0.71
set view 60, 30, 1, 1
set ticslevel 0.5
#fonts
set title font "IsonormD,16"
#set xtics font "IsonormD,16"
set ytics font "IsonormD,16"
set key font "IsonormD,16"
set xlabel font "IsonormD,16"
set ylabel font "IsonormD,16"
after this come only labels and the plot command. Sorry it seems I can't add a picture but would be thankful for advice.
You can unset those mirrored tics with
set tics nomirror
or add the nomirror option to your other ytic and xtic settings.

Gnuplot Multiplot Individual Plot Sizes + Labels

I am currently trying to produce a decent multiplot in Gnuplot. Sadly I ran into some problems.
As the y-axis for both figures is the same I want to only label and tic it once, however I cant remove those from only the left plot.
Secondly I want to increase the width of the left plot while decreasing the one of the right.
Here is a picture of what I got so far, the code is below.
Plot so far
set term postscript eps enhanced color "Helvetica" 10
set output "dosband.eps"
set title "Bandstructure and Density of States"
#
set multiplot layout 1,2 \
margins 0.075,0.98,0.1,0.98 \
spacing 0.02,0.08 #margins: left,right,bottom,top; spacing: vertical, horizontal
set title "Bandstructure"
plot 'plotband.dat' using 1:2 with lines lt 1 lw 0.5 linecolor rgb "black" notitle
set xlabel "Density [states/eV]" #dont ask me why I have to swap the xlabels around
set ylabel "Energy [eV]"
#
set title "Density of States"
plot 'plotdos.dat' using 1:2 with lines lt 1 linecolor rgb "black" notitle
set xlabel "K-Points"
unset multiplot
Thanks in advance for any answers!
As noted by #Christoph, using explicit margins is one of the solutions. In your particular case, you could proceed as:
#dimensions are in screen units
width_left = 0.48
width_right = 0.25
eps_v = 0.12
eps_h_left = 0.1
eps_h_right = 0.05
unset key
set multiplot
set tmargin at screen 1. - eps_v
set bmargin at screen eps_v
set lmargin at screen 0.1
set rmargin at screen eps_h_left + width_left
set xr [0:1.4]
set xtics 0,0.2,1.4
set yr [-40:5]
unset ytics
set y2r [-40:5]
set y2tics in mirror
set format y2 "" #draw ticks but no tic labels
set title "Plot 1"
set xlabel "title 1"
plot 1/0
set lmargin at screen 1. - (width_right + eps_h_right)
set rmargin at screen 1. - eps_h_right
set xr [0:100]
set xtics 0,25,100
unset y2tics
set yr [-40:5]
set ytics in mirror
set mytics 1
set title "Plot 2"
set xlabel "title 2"
set ylabel "Energy [eV]"
plot 1/0
This produces:
In case the Energy [eV] label is supposed to be moved completely to the left, one can adjust the spacings/tics accordingly...

multiplot - stacking 3 graphs on a larger canvas

I have been trying very unsuccessfully to stack 3 graphs together in a multi-plot layout on a canvas that is a ratio of 2:3(width by height).
set terminal postscript eps enhanced "Helvetica" 24 color
set output "data.eps"
set timefmt "%s"
#set size 1.0,1.5
#set bmargin 2
#set tmargin 2
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set tmargin 2
set bmargin 0
set ylabel 'Distance'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace1.dat" using 1:3 axes x1y1 title "distances" with lines lw 2 lc rgb 'blue'
set size 1.0,0.5
set bmargin 0
set tmargin 0
set ylabel 'Power (W)'
set format x ""
set ytics nomirror font "Helvetica,10"
set key top
plot "trace2.dat" using 1:2 axes x1y1 title "device" with lines lw 2 lc rgb 'red'
set size 1.0,0.5
set bmargin
set tmargin 0
set xdata time
set ylabel 'Power (W)'
set xlabel 'Time (EST)' offset 0,-2.8 font "Helvetica,32
set format x "%b %d, %H:%M"
set ytics nomirror font "Helvetica,10"
set xtics nomirror rotate by 90 offset 0,-2.0 out font "Helvetica,10"
set key top
plot "trace3.dat" using 1:2 axes x1y1 title "aggr" with lines lw 2 lc rgb 'blue'
unset multiplot
When I do something like above, I get the plot shown below, there's a lot of blank space at the top of the canvas and the 3 multiplot graphs seem to overlap each other.
Any kind of help or pointer will be greatly appreciated.
In order to use a bigger canvas, you must use the size option when setting the terminal, e.g.:
set terminal postscript eps enhanced size 10cm,15cm
set size just changes the plot size relative to your canvas. To see this, consider
set terminal wxt
set size 1.0,1.5
plot sin(x)
Parts of the plot disappear, because it is much too high with respect to the canvas.
To stack three plots with same heights, in my opinion its best to use fixed margins:
set terminal pngcairo size 600, 900
set output 'stacking.png'
set lmargin at screen 0.15
set rmargin at screen 0.95
TOP=0.98
DY = 0.29
set multiplot
set offset 0,0,graph 0.05, graph 0.05
set xlabel 'time'
set ylabel 'ylabel 1' offset 1
set tmargin at screen TOP-2*DY
set bmargin at screen TOP-3*DY
set ytics -1000,500,1000
plot 1150*cos(x) title 'First'
set xtics format ''
unset xlabel
set ylabel 'ylabel 2' offset 0
set tmargin at screen TOP-DY
set bmargin at screen TOP-2*DY
set ytics -100,50,100
plot 101*sin(x) title 'Second'
set ylabel 'ylabel 3' offset -1
set tmargin at screen TOP
set bmargin at screen TOP-DY
set ytics -8,4,8
plot 10*sin(2*x) title 'Third'
unset multiplot; set output
The result is (with 4.6.3):
In order to avoid overlapping labels of the ytics, you must change the range where the tics are drawn, e.g. with set ytics -100,50,100, which puts ytics between -100 and 100 in steps of 50. Using set ytics rangelimited doesn't work
To increase the distance between the plot curve and the border, use set offset with graph coordinates, like done in the above script.
I started with the lowest plot, because only that has x labels and an xlabel.
You need to use set origin, too.
set terminal postscript eps enhanced
set output "data.eps"
set size 1.0,1.5
set multiplot layout 3,1
set size 1.0,0.5
set origin 0,1
...
plot ...
set size 1.0,0.5
set origin 0,0.5
...
plot ...
set size 1.0,0.5
set origin 0,0
...
plot ...
unset multiplot

Resources