I want my (gnu)plot to have a multi-line title. I would like the title to be centered (i.e. the distance from the center of the widest title line to the edges should be equal), but not to have each line centered independently of the others, which is the default behavior; I want to have the title lines left-aligned and centered only as a block.
How can I achieve this?
This is a bit tricky. As said in the gnuplot documentation:
The `set title` command produces a plot title that is centered at the top of
the plot. `set title` is a special case of `set label`.
Although the label
command accepts a justification parameter, e.g.
set label "mylabel" right
title
does not: it is hard-set to be centered. The workaround I have is to use a label
at the position where the title would be. To make multiple lines use a newline (\n
) within double quotes.
set title "\n"
set label 1 "first line\nsecond line" at graph 0.5,1.125 left
The dummy set title
command is so that gnuplot adjusts the top margin for a two-line title. I found that that position (0.5,1.125) reproduces the default title position well. This won't center the label around the middle of the plot, though--it will be left- or right-justified to the center line. The workaround would be to manually adjust the x-position of the label:
set title "\n"
shift = 0.05 # manually adjust
set label 1 "first line\nsecond line" at graph (0.5-shift),1.125 left
Another approach is to use a fixed width font and make all line the same length.
set term pngcairo size 800,600 font "Courier,10" enhanced crop
set title "\
Synchronic \n\
(. orange) signal columns \n\
(+ green) planar signal \n\
(. red) paraboloid \n\
(x black) intersection \n\
(| black) detection "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With