[Python] 2D plots in plotly cannot show small variations

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have to plot some kind of graphs to represent the data below:

    [[ 0. , 234. , 568.33333333, 881.66666667],
    [ 0. , 234.66888889, 569.44555556, 865.03806017],
    [ 0. , 235.33627407, 570.06910753, 849.9592539 ],
    [ 0. , 235.9989178 , 570.2632452 , 836.28943309]]


    I tried the below code of plotly.

    import numpy as np
    from plotly.subplots import make_subplots
    import plotly.graph_objects as go
    from pathlib import Path
    import os
    import plotly.io as pio

    Smax = 1000
    T = 1

    classical_2d_without_boundary = np.array([[ 0. , 234. , 568.33333333, 881.66666667],
    [ 0. , 234.66888889, 569.44555556, 865.03806017],
    [ 0. , 235.33627407, 570.06910753, 849.9592539 ],
    [ 0. , 235.9989178 , 570.2632452 , 836.28943309]])

    n_rows, n_cols = classical_2d_without_boundary.shape
    x = np.linspace(0, Smax, n_cols)
    y = np.linspace(T, 0, n_rows)

    x, y = np.meshgrid(x,y)
    fig = make_subplots(rows= 1, cols = 1)
    quantum_contour = go.Contour(
    z=classical_2d_without_boundary,
    x=x[0, :], # assuming x is 2D after meshgrid
    y=y[:, 0], # assuming y is 2D after meshgrid
    colorscale='Inferno'

    )

    fig.add_trace(quantum_contour, row = 1, col = 1)

    fig.update_layout(
    title_x=0.5,
    title_font = dict(size=40),
    xaxis_title="x-axis",
    yaxis_title="time (Year)",
    height=900,
    width=855, # Earlier it was 750
    xaxis_title_font = dict(size=36),
    yaxis_title_font = dict(size= 36),
    legend_title_font= dict(size=36),
    font= dict(size=30),
    paper_bgcolor ='white',

    margin=dict(l=20, r=20, t=350, b=20)
    )
    fig.update_xaxes(title_font=dict(size=24))
    fig.update_yaxes(title_font=dict(size=24))


    for annotation in fig['layout']['annotations']:
    annotation['font'].update(size= 40)
    annotation.update(y=1.02) # Increase the y value to move the title up

    # display
    fig.show()


    The graph obtained is as below. My problem is that small variations in values along the columns are not at all captured and visible in the graph generated. Can something be done or some other way a 2D graph can be drawn with plotly that even these variations are very clearly visible? [​IMG]

    Continue reading...

Compartilhe esta Página