[Python] PIL image size adjustment

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

  1. Stack

    Stack Membro Participativo

    I want to repeat the drawing made in matplotlib in PIL. Perhaps the problem is that my data format is "4.005,4.006". How to make the same graph in PIL?

    from PIL import Image, ImageDraw
    import numpy as np
    N = 461
    x = np.linspace(0, 4*np.pi, N)
    y = np.sin(x)
    y=y+50
    im = Image.new('L', (N, N))
    draw = ImageDraw.Draw(im)
    for i in range(len(x)-1):
    draw.line((x,y, x[i+1], y[i+1]),fill='red',width=2)
    im.show()
    # this is the graphic i want to get
    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    ax.plot(x, y)
    plt.show()


    Thanks in advance

    Continue reading...

Compartilhe esta Página