Search code examples
gnuplot

Adding y-axis to multiple offset ytics in gnuplot?


I am searching for a while to get my plot done as I like to have it. Actually, I have a left y-axis and two right y-axis based on the example given here: How to plot multiple y-axes? The information I got there did the job as I would like to have it. However, in my plot I would like to have the y-axis for the 2nd y-values on the right hand side too. I was searching around and found this one: multiple Y axis - margin which is not related to gnuplot. So right now I don't know how to do it except, I will use a vector and build the axis myself which might be not accurate in terms of positioning and not the best way to go. The question now is, if I can move the right border of the graph using an offset like I do it with the ytics and ylabels? The help of gnuplot does not provide anything for the »border« but I might also search at the wrong place.

The picture and gnuplot script is given below. However, I am not allowed to show the graphs but it does not play a role here. To sum up: I would like to have the red added line in my eps file at the end and I am wondering if this is possible without using arrows and building it myself. In addition I hope that this question may be relevant for others and was not asked and solved previously. Otherwise my search-investigation was bad. Thank you in advance.

#!/bin/gnuplot
#
# Tobias Holzmann
# 05.09.2017
# Multiplot for 3 y-axis
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

clear
reset

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set output "PowerControl.tex"
set terminal epslatex
set key nobox
set ytics out
set y2tics out
set ytics nomirror

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set style line 1 lw 1.7 lc rgb 'black' ps 0.7 pt 7
set style line 2 lw 1.5 lc rgb 'black'
set style line 3 lw 1.3 lc rgb 'black' dashtype 4

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set multiplot
set xrange [0:60]
set rmargin screen 0.8
set lmargin screen 0.10

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set xlabel "Time [s]"
set ylabel "Amount of inserted energy [-]"
set ylabel offset 3,0
set yrange [0:.4]
set ytics \
("None" 0.00, "" 0.05, "" 0.1, "" 0.15, "Moderate" 0.2, \
 "" 0.25, "" 0.3, "" 0.35, "High" 0.4)

unset y2tics

set key at graph 0.95,0.22
set key height 0.3

plot \
"timePower" using 1:2 w lp ls 1 t 'Energy insertion'

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

#unset ytics
#unset xtics
unset ylabel

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set grid
set y2tics 10
set y2tics out
set y2range [0:80]
set y2label "Von Mises Stress [MPa]"
set key at graph 0.95,0.315
set key height 6

plot \
"timeVonMises" using 1:2 w l ls 2 t 'Von Mises Stress' axis x1y2

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

unset grid
unset ytics
unset ylabel

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

set y2tics 75
set y2range [0:600]
set y2tics offset 8, 0
set y2label "Maximum Temperature [$^{\\circ} $C]" offset 8,0
set key at graph 0.95,0.10
set key height 0.3

plot \
"timeTMax" using 1:($2-273.15) w l ls 3 t 'Temperature' axis x1y2

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

unset multiplot

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Multiplot with Gnuplot without 2nd y-axis

PS: Based on my low level of reputation points, I am not allowed to put the picture directly (unfortunately).


Solution

  • After checking the manpage of gnuplot etc. I think there is no possibility how I would like to have it. However, a fast an easy workaround is using (as already mentioned vectors with do [] {}. My suggestion is as follows:

    set arrow 1 from graph 1.20,0 to graph 1.20,1 nohead lw 1
    
    do for [i=0:8] {
    set arrow from graph 1.20,i/8. to graph 1.21,i/8. nohead lw 1
    }
    

    The outcome is given in the picture above (or link). Maybe someone can use it for the individual plots one may want to make. If someone knows an better solution, please let us know.

    Kind regards Tobias

    3rd y-axis with arrows and do