I want to put xlabel and ylabel beside their axis at right and above respectively. then I want to set ytics beside the axis not at the left.
Here is my data.
#!usr/bin/gnuplot
unset border
set xzeroaxis
set yzeroaxis
set polar
set nokey
set xtics 0.05
set ytics 0.01
set autoscale fix
set label " k=0.2 " at 0.012, 0.0095
set label " k=0.3 " at 0.022, 0.015
set label " k=0.4 " at 0.032, 0.025
#unset border
#set notics
unset xtics
set ytics
set xlabel "kx"
set ylabel "ky"
plot "T1.txt" u 1:2 w l ,"T2.txt" u 1:2 w l , "T3.txt" u 1:2 w l
It sounds like you want to produce the following plot
Gnuplot has 2 x axes and 2 y axes names x1, x2, y1, and y2. When you just specify the x or y axis, you are actually working with the x1 and y1 axis. The other two are opposite. So to get the labels as you want, we just use the x2 and y2 labels
set x2lab "kx"
set y2lab "ky"
As far as the y-axis marks, gnuplot can put them on the border or on the axis (see help xtics, ytics are similar). Thus, to put the ytics on the axis itself, we just issue
set ytics axis
Related
Is there a way to align vertically the y labels of in gnuplot's multiplot so that they are below each other? The problematic example is below (the red line is annotation showing the problem):
set xrange[0:10]
set multiplot layout 2,1 margins 0.1,0.95,0.1,0.95 spacing 0,0
set ylabel "y1\nlabel"
set ytics
set format y "%.2f"
plot -1000*cos(x)**2 w l lt 4 lw 2
set ylabel "y2\nlabel"
set format y "%.1f"
plot cos(x) w l lt 5 lw 2
unset multiplot
which generates:
And I would like to automatically position the labels such, that the red annotated line "touches the same text". Note that I am really interested in automatic way or more correct way that a workaround using a trial and error with set ylabel "lable" offset -x,0
As you already noted, you can set an offset to the x- or y-label (check help xlabel), however, no absolute position.
This you can do with setting your own label. You can set the position relative to the screen and/or relative to the graph. gnuplot keeps these values for the second plot, no need to specify again. Check help label.
Check the following example:
Code:
### align ylabels in multiplot
reset session
set xrange[0:10]
set multiplot layout 2,1 margins 0.15,0.95,0.1,0.95 spacing 0,0
set format x ""
unset ylabel
set label 1 "y1\nlabel" at screen 0.02, graph 0.5 center rotate by 90
set ytics 200
set ytics add ("" -1000) # remove -1000
set format y "%.2f"
set grid x,y
plot -1000*cos(x)**2 w l lt 4 lw 2
set format x
set label 1 "y2\nlabel"
set ytics 0.4
set format y "%.1f"
plot cos(x) w l lt 5 lw 2
unset multiplot
### end of code
Result:
Hi I am trying to plot a figure like this:
The right side
The line is not importand, it could be a sine curve or anything like that
thanks!
The gnuplot keyword is rangelimited
set xtics nomirror rangelimited
set ytics nomirror rangelimited
set border 3 # only left + bottom
set offset 5,5,5,5 # this much space between axes and data on all sides
plot 'hull.dat' with points notitle
I don't know if there were a feature like that. What you can do is to manually define the x and y tics, remove them from the top and right side, remove the axis all 4 sides, and then draw where you need them.
Here is an example that plots a range from x^2, and showing only the relevant axis range.
f(x) = x>2 ? ( x<4 ? x**2 : 1/0) : 1/0
set xrange [0:5]
set yrange [0:20]
set ytics 4,2,16 nomirror
set xtics 2,1,4 nomirror
unset border
set arrow from 2,0 to 4,0 nohead
set arrow from 0,4 to 0,16 nohead
p f(x)
It looks like:
The idea was from here: http://www.phyast.pitt.edu/~zov1/
I'm able to put an x axis on the top of a graph in gnu plot via
set x2label "label" and
set x2tics
I have a column of data of data1 values and I'd like to plot these values multiplied by two on the upper x axis against data data2 in the lower x axis. Both data1 and data2 are in the same data file. Here is some sample data
data2 data1
20 1.2e-2
40 3.0e-3
60 1.4e-3
... ...
I'd like to plot 2*data1 on upper axis against data2 on lower axis. Preferably, I'd like to just put a tick mark on the 2*data1 axis for every data2 value. On the y axis I will plot some other quantity against data2 but all I want to ask about here is how to plot x2 versus x1.
Thanks!
still guessing what exactly you want. Maybe we'll find out faster with this example.
reset session
$Data <<EOD
# x2 x1 y
20 1.2e-2 1
40 3.0e-3 2
60 1.4e-3 3
EOD
set key top center
set xtics nomirror
set x2tics nomirror
plot $Data u ($1*2):3 axes x2y1 w lp pt 7 title "y-data vs. x2-axis", \
'' u 2:3 axes x1y1 w lp pt 7 title "y-data vs. x1-axis"
Result:
Edit:
You can link x1 and x2 axes via a function (in the example below conversion between nm and eV) and then set your x2tics as desired.
Graph1: corresponding "odd" values from x1,
Graph2: "even" values by given interval x2tics 0.2,
Graph3: manual setting of x2tics.
Example:
### linked axes x1, x2
reset session
set xlabel "Wavelength / nm"
set xtics nomirror
set x2label "Energy / eV"
set x2tics nomirror
set link x via 1239.8/x inverse 1239.8/x
set ylabel "Intensity / a.u."
set ytics 0.2
set samples 400
Spectrum(x) = exp(-(x-500)**2/(400))
set xrange[380:780]
set multiplot layout 3,1
set format x2 "%.2f"
plot Spectrum(x) w l title "Spectrum"
set format x2 "%.1f"
set x2tics 0.2
replot
set x2tics ()
myTics = "1.7 1.8 1.9 2.0 2.1 2.3 2.5 2.7 3.0"
do for [i=1:words(myTics)] { set x2tics add (word(myTics,i) real(word(myTics,i))) }
replot
unset multiplot
### end of code
Result:
Creating a heatmap with gnuplot, I want to have the tic labels read from the datafile on top and right of the heatmap, but setting axes x2y2 doesn't work as expected.
Example data file:
. sample1 sample2 sample3
gene1 10 0 17
gene2 11 2 21
gene3 9 27 0
Using
plot "data.csv" matrix rowheaders columnheaders with image
I get this plot, which is fine:
However, if I want to have the tic labels on the x2 and y2 axes, using i.e.
unset xtics
unset ytics
set x2tics
set y2tics
plot "data.csv" matrix rowheaders columnheaders using 1:2:3 axes x2y2 with image
gnuplot uses numbers instead of my labels:
Is there a way to attach the tic labels read from the file to the x2 and y2 axis?
You have to set x2label and y2label:
set x2label "Some label"
set y2label "Some other label"
plot sin(x) notitle axes x2y2
gives
If you also want to move the tic marks to the upper and right side, then you have to enable them for the x2 and y2 axes and disable them for x and y:
set x2label "Some label"
set y2label "Some other label"
unset xtics
unset ytics
set x2tics
set y2tics
plot sin(x) notitle axes x2y2
gives
Update
Thanks for editing the question. It looks like your main question is whether you can use the labels read from the data file for the x2label and y2label. I am not sure if that is possible; it seems that the rowheaders and columnheaders options always refer to the first coordinate system.
As a workaround you can stick to xlabel/ylabel, and move them to the other side of the graph. This might require playing with the margins a little:
set tmargin 2
set lmargin 0.5
set rmargin at screen 0.75
set colorbox user origin screen 0.88, graph 0 size screen 0.05, graph 1
set xtics offset 0, graph 1.07
set ytics offset graph 1.15, 0
plot "data.csv" matrix rowheaders columnheaders with image
gives
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...