[Python] Heatmap of dataset with 3 1-dimensional arrays?

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

  1. Stack

    Stack Membro Participativo

    I have a dataset with values for X, Y and Z, where each value in an array corresponds to a single value in the others (X corresponds to Y and Z). I want to plot that as a heatmap similar to this:

    [​IMG]

    Where I convert X and Y to polar coordinates and the color represents the value of Z. How can I do this? All the solutions I found are for cases where each X corresponds to multiple values of y, or Z is already a mesh, which is not my case.

    The following code is an example of what I've been trying.

    import numpy as np
    import matplotlib.pyplot as plt
    n = 5
    z = np.linspace(0, 5, n)
    x = np.linspace(-1, 1, n)
    y = np.linspace(-1, 1, n)

    r = np.sqrt(x**2 + y**2)
    th = np.arctan2(y, x)

    fig, ax = plt.subplots(subplot_kw={'projection':'polar'})
    ax.pcolormesh(x, y, z, shading='nearest', vmin=z.min(), vmax=z.max())
    X, Y = np.meshgrid(x, y)
    ax.plot(X.flat, Y.flat, 'o', color='m')
    plt.show()

    Continue reading...

Compartilhe esta Página