Chart Title Position

For some reason, my chart title is appearing on the LEFT side by default. I looked up documentation to position the chart title. I came across some pages where some development work was performed to add position attribute to chart layout.title:

I also found a Plotly documentation page where the layout.title attributes are defined:

However, when I try to use the position attribute in my code, I get an error. Here is my code:

layout = {
‘title’:{‘text’:‘Basic Chart 1’, ‘font’:{‘family’:‘Arial Black’, ‘color’:‘black’, ‘size’:16}, ‘position’:‘middle center’}
}

Here is the error:

File “C:\Users\Lotus\Anaconda3\envs\dash-env\lib\site-packages\plotly\graph_objs\layout_init_.py”, line 7999, in init
self._process_kwargs(**dict(arg, **kwargs))

File “C:\Users\Lotus\Anaconda3\envs\dash-env\lib\site-packages\plotly\basedatatypes.py”, line 2899, in _process_kwargs
self._raise_on_invalid_property_error(*invalid_kwargs.keys())

File “C:\Users\Lotus\Anaconda3\envs\dash-env\lib\site-packages\plotly\basedatatypes.py”, line 3529, in _raise_on_invalid_property_error
prop_descriptions=self._prop_descriptions,

ValueError: Invalid property specified for object of type plotly.graph_objs.layout.Title: ‘position’

Can you please advise how to resolve the problem relating to positioning the chart title. I am using line chart. The version of Plotly is 4.1.1. I updated the Plotly version just yesterday.

Many Thanks !

I have solved the problem by using ‘x’, ‘xanchor’, ‘y’,‘yanchor’:

‘title’:{‘text’:‘Basic Chart 1’, ‘font’:{‘family’:‘Arial Black’, ‘color’:‘black’, ‘size’:16}, ‘x’:0.5, ‘xanchor’:‘center’, ‘y’:0.98, ‘yanchor’:‘top’},

More info on the relevant attributes:

1 Like