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
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:
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:
I'm trying to plot two different sets of data on the same graph using gnuplot. The first set must be plotted as boxerrorbars, and the second one as linespoints. But, when I run the code bellow on gnuplot I get the following error:
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: warning: Skipping data file with no valid points
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
^
"/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.gnu", line 20: all points y2 value undefined!
The code:
set terminal pngcairo enhanced font 'arial,10' fontscale 1.5 size 1024, 768
set output '/home/flav/salaak/src/www/plots/signature.ranking.1.EnergyPKG.png'
unset border
set grid
set style fill solid 0.25 noborder
set boxwidth 0.5 absolute
set title 'Ranking 1 '
set xlabel 'Query.Job'
set ylabel 'EnergyPKG [W]'
set style histogram errorbars gap 2 lw 1
set style data histograms
set xrange [-0.5:3]
set yrange [0:]
set key under autotitle nobox
set ytics nomirror
set y2tics nomirror
set y2range [0:]
set y2label 'Data Size [bytes]'
plot '//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars fc rgb 'forest-green' title 'EnergyPKG [W]' axes x1y1, \
'//home/flav/salaak/src/www/plots/ranking.1.EnergyPKG.dsz.dat' u 1:2 w linespoints t 'Data Size bytes' axes x1y2
ranking.1.EnergyPKG.dat:
q22.2 23.0008220833333 0.237935519166793
q16.2 22.988090297619 1.18050606267611
q07.4 10.6937465361916 0
ranking.1.EnergyPKG.dsz.dat:
q22.2 23359824
q16.2 1987871
q07.4 38
I can't figure out where the problem really is.
The values in the first column aren't valid numerical values, you must use the zeroth column also when plotting the linespoints (as you already do for the boxes):
dir ='/home/flav/salaak/src/www/plots/'
plot dir.'ranking.1.EnergyPKG.dat' using 0:2:3:xtic(1) with boxerrorbars axes x1y1,\
dir.'ranking.1.EnergyPKG.dsz.dat' u 0:2 w lp axes x1y2
And, please restrict the script you post to a bare minimum, which however still shows the problem. All those ranges, labels, tic settings etc are superfluous and make it more difficult to identify the problem.
I saw this graph and only for the curiosity sake was wondering whether it was possible to plot figure with multiple y-axis as in the figure
Many thanks!
As andyras wrote, you can use the second y-axis if you only have two datasets. In this case, you also need to to
set ytics nomirror # remove the tickmarks of the left ayis on the right side
set y2tics # make the right y-axis 'visible'
If you want to plot more than one dataset, I would suggest to use multiplot. You can overlay several independent plots and put a unique offset to the y-axis for each of them.
However, you need to take care that the number of y-tics and y-tick positions is the same.
Plot:
(I did not care about the key here, this still needs adjustment)
Code:
set multiplot
set xrange[0:10]
# We need place to the left, so make the left margin 30% of screen
set lmargin screen 0.3
##### first plot
set ytics 0.4
set yrange[-1.2:1.2]
set ylabel "Voltage" textcolor rgb "red"
plot sin(x)
##### Second plot
set ytics 1
set yrange[-3:3]
set ytics offset -8, 0
set ylabel "Current" offset -8, 0 textcolor rgb "green"
plot 3*cos(x) linecolor 2
##### Third plot
set ytics 0.5
set yrange[-1.5:1.5]
set ytics offset -16, 0
set ylabel "Power" offset -16, 0 textcolor rgb "blue"
plot 3*sin(x)*cos(x) linecolor 3
unset multiplot
Yes, you can have two y axes for free, e.g.
plot x, x**2 axes x1y2
The axes specification lets you put things on x1y1, x2y1, etc. If you want more than two things plotted on the same y axes you have to normalize things yourself:
plot 'data1.dat' using 1:($2/MAX_1), \
'data2.dat' using 1:($2/MAX_2), \
'data3.dat' using 1:($s/MAX_3)
The variables MAX_X can be precalculated by using the stats command in gnuplot 4.6+, or you can put them in manually.
I use gnu plot to draw a multiplot and in my script I set the y label like that:
set ylabel "foobar"
Now every plot in the multiplot has a dedicated y label on their y axis. However, I would like to have only one y label for all the plots in the multiplot and center that label also on the common y axis. How can I do that? The multiplot layout I use is a 7.1 So all the plots have the same y axis.
The simplest way is to make the first plot, then turn off the y label:
set ylabel 'foo'
set multiplot
plot 'data1.dat'
unset ylabel
plot 'data2.dat'
plot ...
unset multiplot
This will make the x-dimension of the first plot different from that of all the other plots, so you may have to play with the margins if you want all the plots the exact same size.
Plot the individual panels of reduced size without labels but with border, tics and title, then define a full-sized panel with labels but without border, tics and title.You may have to plot a dummy function (1/0).
Global label workaround
This is not ideal, but if you desperate like me, you can use a rotated global label + larger left margins:
#!/usr/bin/env gnuplot
label_label_size = 14
set terminal png
set output "gnuplot.png"
set multiplot layout 2,1 title "Multiplot with one ylabel" font ",18"
set lmargin 10
set label "My y-label" at screen 0.05,0.5 center front rotate \
font "," . label_label_size
plot sin(x)
set xlabel 'My x-label' font "," . label_label_size
plot cos(x)
Here is a realistic application that motivated me to do this: Heap vs Binary Search Tree (BST)
Tested in gnuplot 5.2 patchlevel 6, Ubuntu 19.04.
This is basically the suggestion from Fabian Claremont's answer, but (for beginners) put into code and visualized. Actually, Ciro Santilli's solution is even shorter.
Tested with gnuplot 5.2. For gnuplot 4.6 (the time of OP's question), replace reset session with reset and set margin 8,-1,1-1 with set lmargin 8 and set bmargin 1.
Code:
### Multiplot with single y-label
reset session
unset key
set sample 500
set multiplot layout 7,1
unset ylabel
set linetype 1 lc rgb "red"
set margins 8,-1,1,-1 # left, right, bottom, top (-1=auto)
set ytic 1.0
set title "Plot 1" offset 0,-1
plot sin(1*x)
set title "Plot 2" offset 0,-1
plot sin(2*x)
set title "Plot 3" offset 0,-1
plot sin(3*x)
set title "Plot 4" offset 0,-1
plot sin(4*x)
set title "Plot 5" offset 0,-1
plot sin(5*x)
set title "Plot 6" offset 0,-1
plot sin(6*x)
set title "Plot 7" offset 0,-1
plot sin(7*x)
set lmargin -1 # automatic lmargin
unset title
set origin 0,0
set size 1,1
set border 0
unset tics
set ylabel "This is a centered y-label"
plot [][0:1] -1 # plot a dummy line out of range
unset multiplot
### end of code
Result: