[Python] How to resize graph and make it fit x in the range of 15 to 30?

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

  1. Stack

    Stack Membro Participativo

    import numpy as np
    import matplotlib.pyplot as plt
    import scipy

    x4=[30,30.5,31,31.2,31.6,30.4,31,31.75,32.5,33,33.2,33.6,32.5,34.5]
    y4=[10.5,11,11.5,12,12.6,10.4,10,10.2,10.75,11.5,12,12.6,10,11]
    t4=np.linspace(0, len(x4), num=len(x4), endpoint=True)
    f9 = scipy.interpolate.interp1d(t4,x4, kind='cubic')
    f10 = scipy.interpolate.interp1d(t4,y4, kind='cubic')
    tnew4 = np.linspace(0, len(x4), num=100000, endpoint=True)

    x5=[34.5,35.5,34.5,34.5,36.5,37.2, 37.5,36.5,36,37.5]
    y5=[11,12.6,11,10,11,12,12.6,11,10,10.5]
    t5=np.linspace(0, len(x5), num=len(x5), endpoint=True)
    f11 = scipy.interpolate.interp1d(t5,x5, kind='cubic')
    f12 = scipy.interpolate.interp1d(t5,y5, kind='cubic')
    tnew5 = np.linspace(0, len(x5), num=100000, endpoint=True)

    x6=[37.5,38,39,39.5,38,40,41.5,40.3,40,41,42,42.5,43,43.7,42]
    y6=[10.5,11,12,12.8,10,11,12.7,11,10,10.5,11,11.5,12,13,10]
    t6=np.linspace(0, len(x6), num=len(x6), endpoint=True)
    f13 = scipy.interpolate.interp1d(t6,x6, kind='cubic')
    f14 = scipy.interpolate.interp1d(t6,y6, kind='cubic')
    tnew6 = np.linspace(0, len(x6), num=100000, endpoint=True)

    #a...
    x7=[42,43.5,45.5,46.5,47.8,48.5,40,39,38.5,37,34,28,23,20,19,20,23,30,33]
    y7=[10,11,13,14,16,17,6.5,7,8,9,10,11,11,10,9,7,6.5,6.5,7]
    t7=np.linspace(0, len(x7), num=len(x7), endpoint=True)
    f15 = scipy.interpolate.interp1d(t7,x7, kind='cubic')
    f16 = scipy.interpolate.interp1d(t7,y7, kind='cubic')
    tnew7 = np.linspace(0, len(x7), num=100000, endpoint=True)

    x8=[48.5,48.2,45,40.5]
    y8=[17,16,12,6]
    t8=np.linspace(0, len(x8), num=len(x8), endpoint=True)
    f17 = scipy.interpolate.interp1d(t8,x8, kind='cubic')
    f18 = scipy.interpolate.interp1d(t8,y8, kind='cubic')
    tnew8 = np.linspace(0, len(x8), num=100000, endpoint=True)

    x9=[16,40,45,49]
    y9=[9,8,8,8]
    t9=np.linspace(0, len(x9), num=len(x9), endpoint=True)
    f19 = scipy.interpolate.interp1d(t9,x9, kind='cubic')
    f20 = scipy.interpolate.interp1d(t9,y9, kind='cubic')
    tnew9 = np.linspace(0, len(x9), num=100000, endpoint=True)

    plt.xlim(5,50)
    plt.ylim(0,30)

    plt.plot(f9(tnew4), f10(tnew4), 'b-',f11(tnew5), f12(tnew5), 'b-',
    f13(tnew6), f14(tnew6), 'b-',f15(tnew7), f16(tnew7), 'b-',f17(tnew8), f18(tnew8), 'b-',
    f19(tnew9), f20(tnew9), 'b-')
    plt.show()


    I have to draw a weird graph and move it to a specific range. Does anyone know how to resize my graph and make it fit x in the range of 15 to 30? I tried to find something on the internet, but many answers try to use figsize, which doesn't fit my task.

    I have to move the graph to the boundaries marked in the photo.

    Thanks for your help

    [​IMG]

    Continue reading...

Compartilhe esta Página