社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

用python绘制曲面[复制]

Βασιλης ΙωσηφιδΠ• 5 年前 • 1497 次点击  

这个问题已经有了答案:

我试图绘制一些数据,其中包括4个变量。我用了两种方法,一种是散点图,另一种是曲面图。问题是当我使用surface时,数据丢失了。我想这和颜色设置有关。

对于散点图,我使用:

def scatter3d(x,y,z, cs, colorsMap='jet'):
   cm = plt.get_cmap(colorsMap)
   cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
   scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
   fig = plt.figure()
   ax = Axes3D(fig)
   ax.scatter(x, y, z,c=scalarMap.to_rgba(cs))
   ax.set_xlabel('Thita1')
   ax.set_ylabel('Thita2')
   ax.set_zlabel('Fairness (%)')
   scalarMap.set_array(cs)
   fig.colorbar(scalarMap,label='Error Rate (%)')
   plt.show()

enter image description here

我想把它转换成一个曲面图,使用这个:

   def surfacePlot(x,y,z, cs, colorsMap='jet'):
    cm = plt.get_cmap(colorsMap)
    cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
    scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_surface(x, y, z, facecolors=scalarMap.to_rgba(cs))
    ax.set_xlabel('Thita1')
    ax.set_ylabel('Thita2')
    ax.set_zlabel('Fairness')
    scalarMap.set_array(cs)
    fig.colorbar(scalarMap,label='Error Rate (%)')
    plt.show()

但是,这将导致空网格:

enter image description here

尽管轴已从矢量中接收到最小值和最大值,但这些点已丢失。我做错什么了?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48224
 
1497 次点击  
文章 [ 1 ]  |  最新文章 5 年前