[Python] Moving the Scientific Notation Offset of a Pyplot Graph below the top Spine

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

  1. Stack

    Stack Membro Participativo

    I'm stacking multiple graphs using matplotlib-pyplot. This is my minimal reproducable example:

    from matplotlib import pyplot as plt
    from numpy import linspace, sqrt, pi
    fig, ax = plt.subplots(3, 1, sharex=True)
    plt.subplots_adjust(hspace=0)


    def zr(w0, l):
    return pi*w0**2/l

    def w0(l, L, R):
    return sqrt(l/pi * sqrt(L*(R-L)))


    def width(z, l):
    return w0(l, 0.55, 1) * sqrt(1 + (z / zr(w0(l, 0.55, 1), l))**2)

    x = linspace(0, 1, 5)
    y = width(x, 5.54e-6)

    for i in range(3):
    #Do some analysis here, then plot the fit

    ax.set_xlabel("z / m")
    ax.set_ylabel("$d(w)$ / mm")
    ax.ticklabel_format(axis='y', style='sci', scilimits=(0, 0))
    ax.grid("both", linestyle=":")

    #The Fix i tried:
    ax.get_yaxis().get_offset_text().set_position((0,0.7))

    ax[1].errorbar(x, y, xerr = 0.025, yerr = 0.2*1e-3, color = "black", linestyle = "")

    plt.show()


    Unfortunately in my example, the offset modifier intersects with the data in the graph above.
    To fix that I want to move it below the spine. I originally tried this answer, as can be seen above, but I was unable to observe any change.

    [​IMG]

    Continue reading...

Compartilhe esta Página