[Python] Log plot point not showing in the pyplot

Discussão em 'Python' iniciado por Stack, Março 13, 2025.

  1. Stack

    Stack Membro Participativo

    I want to create a log plot

    However, the result does not show the minor grid and something like this

    [​IMG]

    What can I do with the script. Thank you!

    import matplotlib.pyplot as plt
    import numpy as np

    # Data (x-values and y-values)
    x = np.array([
    3.17E-15, 6.34E-15, 1.27E-14, 2.54E-14, 5.07E-14, 1.01E-13, 2.03E-13, 4.06E-13, 8.11E-13,
    1.62E-12, 3.21E-12, 6.38E-12, 1.27E-11, 2.54E-11, 5.07E-11, 1.01E-10, 2.03E-10, 4.06E-10,
    8.11E-10, 1.62E-09, 3.21E-09, 6.38E-09, 1.27E-08, 2.54E-08, 5.07E-08, 1.01E-07, 2.03E-07,
    4.06E-07, 8.11E-07, 1.62E-06, 3.21E-06, 6.38E-06, 1.27E-05, 2.54E-05, 5.07E-05,
    0.00010144, 0.000202842, 0.000405646, 0.000684463, 0.001242097, 0.001340406,
    0.002024869, 0.002737851
    ])

    y = np.array([
    42, 42, 42, 42, 41.9727, 41.9197, 41.819, 41.6368, 41.332, 40.879, 40.3057,
    39.6555, 38.9779, 38.2946, 37.6106, 36.9265, 36.2423, 35.5579, 34.8729, 34.1871,
    33.5108, 32.8299, 32.1462, 31.4607, 30.7743, 30.0873, 29.4001, 28.7127, 28.0254,
    27.3381, 26.6609, 25.9797, 25.2959, 24.6105, 23.9243, 23.2377, 22.5509, 21.8641,
    21.326, 20.735, 20.6422, 20.223, 19.9095
    ])

    # Create log-log plot
    plt.semilogx(x, y)

    # Labels and title
    plt.xlabel("X (Log Scale)")
    plt.ylabel("Y (Log Scale)")
    plt.title("Log-Log Plot")

    # Add grid lines
    plt.grid(which='both') # 'both' applies to both major and minor ticks
    plt.minorticks_on() # Enable minor ticks

    # Show the plot
    plt.show()


    I want the figure show something like this

    [​IMG]

    Continue reading...

Compartilhe esta Página