Adding annotations to polar-scatterplots

@I194

Starting with Plotly 4.+ we can define subplots with different layout coordinates: polar and cartesian. So we can use a trick to insert annotations below a polar plot. We define a subplot with 2 rows and one column. In the cell
(1,1), of type=β€˜polar’, we insert the polar plot, while in (2,1) , of type=β€˜xy’ (i.e. cartesian) we insert a text as annotation.

Example:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(
    rows=2, cols=1,
    specs=[[ {"type": "polar"}],
           [ {"type": "xy"}]])
        
fig.add_trace(go.Barpolar(theta=[0, 45, 90], r=[2, 3, 1]),
              row=1, col=1)


fig.update_layout(height=600, showlegend=False);

fig.layout
Layout({
    'height': 600,
    'polar': {'domain': {'x': [0.0, 1.0], 'y': [0.575, 1.0]}},
    'showlegend': False,
    'template': '...',
    'xaxis': {'anchor': 'y', 'domain': [0.0, 1.0]},
    'yaxis': {'anchor': 'x', 'domain': [0.0, 0.425]}
})

h = 0.2
vertical_sp = 0.1
fig.update_layout(width= 600, height=650, template='none')
fig.layout.polar.domain.update(y =[h, 1])
fig.layout.yaxis.update(domain =[0, h-vertical_sp], visible=False)
fig.layout.xaxis.update(visible=False, range=[0,1])
fig.layout.annotations =[dict(showarrow=False, 
                              text='Here I insert my annotation',  
                              xref='x',     
                              yref='y',     
                              x=0.,  
                              y=0.15,  
                              xanchor='left',   
                              yanchor='bottom',  
                              font=dict(size=12 ))]
fig.show()

The above figure has no layout template.

With the default β€˜plotly’ template the annotation is displayed on a non-white background:

fig.layout.template='plotly'
fig.show()

If your question refers to annotations inside the polar circle (i.e. annotations inserted in a position given in polar coordinates), that is not available, yet.

2 Likes