Polar plot as inset

Hi there,

I’m trying to insert a Polar plot as inset into a scatter plot. Please see below:

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

#generate subplots
fig = make_subplots(rows=1, cols=2,shared_yaxes=True,horizontal_spacing = 0.01,
                   insets=[{'cell':(1,2),'l': 0.7, 'b': 0.3}])

#add traces
fig.add_trace(go.Scatter(x=[100,200,300], y=[2200,2300,2400],mode='lines+markers'),row=1, col=1)
fig.add_trace(go.Scatter(x=[100,500,300], y=[2200,2300,2400],mode='lines+markers'),row=1, col=2)

#add barpolar
fig.add_trace(go.Barpolar(r=[1,2,3,4],theta=[20,21,22,23],width=6))

This generates the figure below:

However, I want it to be displayed as an inset within the subplot 2 at a specified location (hence insets=… command). So, I replace the last line with this:

fig.add_trace(go.Barpolar(r=[1,2,3,4],theta=[20,21,22,23],width=6),xaxis='x2',yaxis='y2')

And it complains:
TypeError: add_trace() got an unexpected keyword argument β€˜xaxis’

Can someone please help on how to pin the Polar plot to subplot in xy?

Thanks
Vivek

1 Like