【问题标题】:Overlap a heatmap in a 3d Matplotlib plot在 3d Matplotlib 图中重叠热图
【发布时间】:2012-12-09 00:39:57
【问题描述】:

我是 matplotlib 的新手,我不知道在哪里可以找到那个...

我想绘制数据,其中 X 和 Y 是问题的参数,然后 Z 显示使用该参数的问题的解决时间。但在绘图表面上,我想用热图显示问题的难度或可满足性。

有没有办法做到这一点?

谢谢!

【问题讨论】:

    标签: 3d matplotlib plot heatmap


    【解决方案1】:

    取自matplotlib examples

    from mpl_toolkits.mplot3d import Axes3D
    from matplotlib import cm
    from matplotlib.ticker import LinearLocator
    import matplotlib.pyplot as plt
    import numpy as np
    
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    X = np.arange(-5, 5, 0.25)
    xlen = len(X)
    Y = np.arange(-5, 5, 0.25)
    ylen = len(Y)
    X, Y = np.meshgrid(X, Y)
    R = np.sqrt(X**2 + Y**2)
    Z = np.sin(R)
    
    colortuple = ('y', 'b')
    colors = np.empty(X.shape, dtype=str)
    for y in range(ylen):
        for x in range(xlen):
            colors[x, y] = colortuple[(x + y) % len(colortuple)]
    
    surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
            linewidth=0, antialiased=False)
    
    ax.set_zlim3d(-1, 1)
    
    ax.w_zaxis.set_major_locator(LinearLocator(6))
    
    plt.show()
    

    您可以将颜色传递给 3d 曲面图。

    【讨论】:

    • 您能添加一个指向示例页面的链接吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-22
    • 2017-04-12
    • 1970-01-01
    • 2013-07-19
    • 2014-05-17
    • 2017-08-06
    • 2023-01-20
    • 2013-12-24
    相关资源
    最近更新 更多