Adding annotations to polar-scatterplots

Hello, I am using the Plotly Matlab API for plotting a polar scatter-plot. I would like to add text to this plot at different (r,theta) coordinates. As an example, please see the polar scatter-plot at https://plot.ly/matlab/polar-chart/#polar-scatter-chart. If I want to add annotation to this plot at different (r,theta) coordinates, how can I do that? I looked at the examples on text/annotation but they are not for polar scatter-plot. Any help is greatly appreciated.

Annotations are not compatible with polar charts (along with numerous other features) at the moment.

We are planning on making significant efforts into putting polar charts on par with the rest of the library this summer. Stay tuned for more details.

2 Likes

Thank you. Looking forward to the new features.

Are annotations still not working for polar scatter chart?

@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