1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Conditional marker for scatterplot Matplotlib

Discussão em 'Python' iniciado por Stack, Outubro 2, 2024 às 20:03.

  1. Stack

    Stack Membro Participativo

    I am trying to plot x1 and x2 against each other, and if class == 1, then marker should be +, if class == 0, then the marker should just be a dot.

    The file.csv is structured like this, the class column which is the conditional will only be either 1 or 0:

    x1 x2 class
    1 2 0
    9 4 1
    0 5 1
    2 6 0

    Here's the code I have:

    df = pd.read_csv('file.csv')
    print(df)
    x1 = df['x1'].to_numpy()
    x2 = df['x2'].to_numpy()
    class = df['class'].to_numpy()

    figure, ax = plt.subplots()

    for i in range(0,80,1):
    if label > 0:
    ax.plot(x1, color="red", marker='o')
    else:
    ax.plot(x1, color="blue", marker='x')


    This is what the result SHOULD look like: [​IMG]

    Continue reading...

Compartilhe esta Página