[Python] Matplotlib Zorder not respected between Bar and Grid, why?

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

  1. Stack

    Stack Membro Participativo

    My Matplotlib version is 3.7.2

    Here is a code where gridlines zorder > bars zorder:

    import matplotlib.pyplot as plt
    import numpy as np

    # Sample data
    x = np.arange(4)
    y1 = [5, 7, 3, 6]
    y2 = [4, 6, 5, 7]

    # Create figure with 2 subplots
    fig, axs = plt.subplots(1, 2, figsize=(8, 4), dpi=120)

    # Plot on subplot 1
    axs[0].bar(x, y1, color='skyblue', zorder=1.49999)
    axs[0].set_title("Subplot 1")
    axs[0].grid(True, zorder=10)

    # Plot on subplot 2
    axs[1].bar(x, y2, color='salmon', zorder=1.5000001)
    axs[1].set_title("Subplot 2")
    axs[1].grid(True, zorder=10)

    plt.show()


    and the result is :

    [​IMG]

    so it seems there's a boundary of 1.5 for bars zorder ? that's strange

    What is also strange is when i add axs.set_axisbelow(False) on both axes, the boundary seems to be 2.5...

    What am i doing wrong ?

    Continue reading...

Compartilhe esta Página