[Python] Adding 500 circles in a plotly graph using add_shape function takes 45 seconds, how...

Discussão em 'Python' iniciado por Stack, Junho 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to add small circles in a plotly graph. I want to add around 1000 small circles. But to add 500 circles itself it's taking more than 45 seconds. Is there any way to reduce this timing? I hear using d3 lib in javascript will be much faster. But I would like to achieve this using python.

    Please see my code below.

    Data points would be some thing like this,

    -0.0919488188976378 0.4985236220472441 -0.08210629921259843 0.5083661417322834
    -0.11714566929133859 0.4985236220472441 -0.1073031496062992 0.5083661417322834
    -0.1423425196850394 0.4985236220472441 -0.1325 0.5083661417322834


    x0, y0, x1, y1 format.

    The code that adds shaple is

    fig = go.Figure()
    for data in datapoints:
    x0 = data[0]
    y0 = data[1]
    x1 = data[2]
    y1 = data[3]
    fig.add_shape(type="circle",
    xref="x", yref="y",
    x0=x0, y0=y0, x1=x1, y1=y1,
    line_color='gold',
    fillcolor='gold',
    )

    print("--- %s seconds ---" % (time.time() - start_time))


    To code takes around 45 seconds to execute.

    Is there any way to reduce this timing? or is there any other library to achieve this requirement? My requirement is based on some input files (shapes specifications/dimensions), I need to create SVG images using python.

    Thanks in advance.

    Continue reading...

Compartilhe esta Página