[Python] Matplotlib yticks are not rising consecutively

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    import pandas as pd
    df = pd.DataFrame(data)
    print(df)
    #%%
    import matplotlib.pyplot as plt
    from matplotlib.ticker import MaxNLocator
    import numpy as np

    plt.scatter(df['time'], df['mag'], s=25, alpha=.3)
    plt.xlabel("Time")
    plt.ylabel("Magnitude")
    plt.xticks(df['time'], rotation=60)
    plt.gca().xaxis.set_major_locator(MaxNLocator(nbins=20))
    plt.gca().yaxis.set_major_locator(MaxNLocator(nbins=30))
    plt.show()


    So this is the code of my plot and since my df has a huge amounts of data I had some overlapping problem but fixed it with MaxNLocator. Now my y ticks look like the one in the photo but I want them to start from 2 and end with the highest. How can I do it?enter image description here

    Continue reading...

Compartilhe esta Página