Arc Shape with Path

@extraymond, @openafox

You can draw both arcs of circle or ellipse, and filled circle or ellipse calling a function that defines the corresponding svg paths:

import numpy as np
import plotly.graph_objects as go

def ellipse_arc(x_center=0, y_center=0, a=1, b =1, start_angle=0, end_angle=2*np.pi, N=100, closed= False):
    t = np.linspace(start_angle, end_angle, N)
    x = x_center + a*np.cos(t)
    y = y_center + b*np.sin(t)
    path = f'M {x[0]}, {y[0]}'
    for k in range(1, len(t)):
        path += f'L{x[k]}, {y[k]}'
    if closed:
        path += ' Z'
    return path    

fig = go.Figure()

# Create a minimal trace 
fig.add_trace(go.Scatter(
    x=[0],
    y=[0.2],
    marker_size=0.1
));

fig.update_layout(width =600, height=400,
           xaxis_range=[-5.2, 5.2], 
           yaxis_range=[-3.2, 3.2],       
    shapes=[
           dict(type="path",
           path= ellipse_arc(a=5, b=3, start_angle=-np.pi/6, end_angle=3*np.pi/2, N=60),
           line_color="RoyalBlue"),
           dict(type="path",
                path = ellipse_arc(x_center=2, a= 0.5, b= 1.5, closed=True),
                fillcolor="LightPink",
                line_color="Crimson")
        ]
        );
fig.show()

arcs

If a=b youโ€™ll get an arc of circle (if layout.width=layout.height), otherwise an arc of ellipse.

1 Like