Three variables as heatmap

前端 未结 1 1275
旧巷少年郎
旧巷少年郎 2021-01-14 08:48

I want to plot my data as a heatmap which has the following structure:

X = [1,1,1,1,1,1,1,1,1,1], Y = [1,2,3,4,5,6,7,8,9,10] Z = [0.2, 0.33, 0.1, 0.25, 0.0, 0.

1条回答
  •  天涯浪人
    2021-01-14 09:11

    I hope your data is just an example because it will look funny (it's more a sequence of strips; the x-dimension is constant).

    I would recommend the usage of pandas (general data-analysis) and seaborn (matplotlib-extensions) which makes it a bit nicer.

    Code

    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns
    X = [1,1,1,1,1,1,1,1,1,1]
    Y = [1,2,3,4,5,6,7,8,9,10]
    Z = [0.2, 0.33, 0.1, 0.25, 0.0, 0.9, 0.75, 0.88, 0.44, 0.95]
    data = pd.DataFrame({'X': X, 'Y': Y, 'Z': Z})
    data_pivoted = data.pivot("X", "Y", "Z")
    ax = sns.heatmap(data_pivoted)
    plt.show()
    

    Output

    0 讨论(0)
提交回复
热议问题