How to position the title directly above the chart (independently of margin):
"y" : 1,
"yanchor" : "bottom"
(Or specify the same thing in
How does it work?
yref is used to position the title relative to the actual chart (
"paper") and not the container (which would be
y is a value between 0 and 1 which sets the relative position. Setting it to 1 will put the title at the top of the chart; setting it to 0 will put the title at the bottom of the chart etc.
yanchor sets what part of the title will touch its
y location. Without this property the title would now be at the top, but inside the chart (i.e. aligned with the
"top"). We set
"bottom" so that the bottom of the title will be aligned with the top of the chart, i.e. the title will be located precisely above the chart.
For adding a little padding between the title and the chart use the
pad property of the title (look it up in the reference). For vertically positioning the title (e.g. centering it) you can use
xanchor in the same way.