【问题标题】:Issue in plotting a 3d graph绘制 3d 图形时的问题
【发布时间】:2021-11-09 15:55:30
【问题描述】:

我正在努力为四个参数设计一个 3d 图,我有三个参数 x、y 和 z。参数x、y、z在0到1的范围内,k参数为分类值0或1。我的数据格式如下data-csv

代码

data = np.genfromtxt("data.csv", delimiter=",", names=["x", "y","z","k"])
x, y, z = zip(*data)
fig = plt.figure()
ax = plt.axes(projection='3d')
#ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Optimal-Selection')
ax.set_ylim(0,1)
ax.set_zlim(0,1)
surf = ax.plot_trisurf(np.array(x), np.array(y), np.array(z),cmap='viridis')
fig.colorbar(surf,shrink=0.5, aspect=9)
plt.show()

运行时错误:

RuntimeError: Error in qhull Delaunay triangulation calculation: input inconsistency (exitcode=1); use python verbose option (-v) to see original qhull error.

【问题讨论】:

    标签: python matplotlib 3d


    【解决方案1】:

    这是否与您要找的内容相近?

    import numpy as np
    import matplotlib.pyplot as plt
    
    data = np.genfromtxt("data.csv", delimiter=",", skip_header=1)
    list (data)
    x = data [:,0]
    y = data [:,1]
    z = data [:,2]
    
    fig = plt.figure()
    ax = plt.axes(projection='3d')
    #ax = fig.add_subplot(111, projection='3d')
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Optimal-Selection')
    ax.set_ylim(0,1)
    ax.set_zlim(0,1)
    surf = ax.plot_trisurf(x,y,z,cmap='viridis')
    fig.colorbar(surf,shrink=0.5, aspect=9)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多