[Python] Matplotlib Makes Trippy Incorrect plots

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I fill a numpy array with 0 or 1 depending if a computed array indexed value is more or less than a given value. This results in an array of zeros and ones. Matplotlib doesnt think so

    The comparison is computed d=sin(bpi/180)x+sin(api/180)cos(bpi180)*y

    The unique statement prints " unique values in space [0. 1.]"

    Last image shows same code with True/False array instead of 0/1

    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    tan=np.tan
    sin=np.sin
    cos=np.cos
    pi=np.pi
    x=4
    y=3
    Max=.3

    sizeOfSpace=2000
    alpha=np.linspace(-10, 10,sizeOfSpace)
    beta=np.linspace(-10, 10,sizeOfSpace)

    space=np.zeros((sizeOfSpace,sizeOfSpace))
    for i,a in enumerate(alpha):
    for j,b in enumerate(beta):
    d=sin(b*pi/180)*x+sin(a*pi/180)*cos(b*pi*180)*y
    space[i,j]=int(0) if d<Max else int(1)
    plt.imshow(space,cmap=plt.cm.gray)
    plt.colorbar()
    print(f'unique valeus in space {np.unique(space)}')


    [​IMG]

    [​IMG]

    [​IMG]

    Any suggestions how to make the binary image?

    Continue reading...

Compartilhe esta Página