[Python] plt.contour() plots series of lines instead of a contour line

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    I aim to plot a contour plot of flux, but instead of closed contour curves, plt.contour() returns a series of lines with the same height.

    Psi is defined as a np.array and has a 320 by 200 shape.

    fig, ax = plt.subplots()
    r_end = grid_start[0] + grid_step[0] * grid_size[0]
    z_end = grid_start[1] + grid_step[1] * grid_size[1]

    X = np.arange(grid_start[0], r_end, grid_step[0]) # shape (200,)
    Y = np.arange(grid_start[1], z_end, grid_step[1]) # shape (320,)

    x, y = np.meshgrid(X, Y)
    CS = ax.contour(x, y, Psi)
    ax.clabel(CS, fontsize=10)



    The result looks very weird:

    all contours image

    I also created contour plots with some levelling for enhanced visibility.

    contour plot, level 0

    contour plot, level 25

    The desired result is smth like this: desired Psi Contours

    If I reshape the given array to (3200,20) the periodicity is lost, but it is still weird.

    reshaped result

    How can I fix this issue? Thanks for your help.

    Continue reading...

Compartilhe esta Página