[Python] graph_objects.Surface axis tic spacing inconsistent on x and y

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    Given hemi.csv data of:

    244,1000,1500,2000,2500,3000,3500,5000
    0,14,18,-42,-72,-84,-86,-94,-119
    12.5,277,231,185,139,144,150,161,158
    25.1,416,394,370,348,361,374,404,396
    37.6,483,587,633,653,566,585,633,621
    49.8,504,612,733,756,668,691,748,734
    62.4,504,612,733,756,786,749,809,794
    74.9,504,612,733,756,786,814,854,838
    100,504,612,733,756,786,814,880,864


    I have plotly code of:

    import pandas as pd
    import plotly.graph_objects as go

    # Open DataFrame
    df = pd.read_csv('hemi.csv', header=0, index_col=0)
    # Extracting data for the surface plot
    x_data = df.columns.tolist()
    y_data = df.index.tolist()
    z_data = df.values

    # Creating the surface plot
    fig = go.Figure(data=[go.Surface(z=z_data, x=x_data, y=y_data)])

    # Updating layout for axis titles and tick labels
    fig.update_layout(
    scene = dict(
    xaxis = dict(title = 'RPM',
    tickmode = 'array',
    tickvals = x_data,
    ticktext = df.columns),
    yaxis = dict(title = 'TPS',
    tickmode = 'array',
    tickvals = y_data,
    ticktext = df.index),
    zaxis = dict(title = 'torque Nm')
    )
    )

    fig.show()


    I get yaxis 'TPS' spaced as expected with tic spacing of the index values. However the xaxis 'RPM' tic spacing is uniform, ie not proportional to the columns values as desired. Ie, 3500,5000 is the same width as 3000,3500.

    [​IMG]

    In MPL plot_trisurf the tics appear to be uniform, and the plot locations are scaled:

    import matplotlib.pyplot as plt
    from matplotlib import cm
    import pandas as pd
    # Get the data (csv file is hosted on the web)
    data = pd.read_csv('413.csv', header=0, index_col=0)

    # Transform it to a long format
    df=data.unstack().reset_index()
    df.columns=["X","Y","Z"]

    fig = plt.figure()
    ax = fig.add_subplot(projection='3d')
    ax.plot_trisurf(df['Y'],
    df['X'],
    df['Z'],
    cmap=cm.jet,
    linewidth=0.2)
    plt.show()


    [​IMG]

    Continue reading...

Compartilhe esta Página