3D曲面图为空

huangapple go评论50阅读模式
英文:

3D Surface plot is empty

问题

我正在跟随一个关于数据科学的在线课程,该课程使用Plot.ly和Cufflinks来绘制数据。我正在尝试理解表面绘图的工作原理。这是课程作者提供的数据示例:

df3 = pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,20,10],'z':[5,4,3,2,1]})

我尝试像这样绘制它,但图表为空:

df3.iplot(kind='surface', colorscale='rdylbu', x='x', y='y', z='z')

在图表显示中,当我点击"Export to plot.ly"时,生成的电子表格与我的数据集匹配,即x = [1, 2, 3, 4, 5],y = [10, 20, 30, 20, 10],z = [5, 4, 3, 2, 1]。但图表仍然为空。根据数据集,我期望表面绘图包含以下点(按照x、y、z的顺序):

  • (1, 10, 5)
  • (2, 20, 4)
  • (3, 30, 3)
  • (4, 20, 2)
  • (5, 10, 1)
英文:

I am following an online course on data science which uses Plot.ly with Cufflinks to plot data. I am trying to understand how the surface plot works. This is the data sample provided by the course author:

df3 = pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,20,10],'z':[5,4,3,2,1]})

I tried to plot it like this, but the plot comes up empty:

df3.iplot(kind='surface',colorscale='rdylbu', x='x', y='y', z='z')

In the figure display, when I click "Export to plot.ly", the generated spreadsheet matches my dataset, i.e., x = [1, 2, 3, 4, 5], y = [10, 20, 30, 20, 10], and z = [5, 4, 3, 2, 1]. But the figure is still empty. Based on the dataset, I expected the surface plot to contain the following points (in x, y, z order):

  • (1, 10, 5)
  • (2, 20, 4)
  • (3, 30, 3)
  • (4, 20, 2)
  • (5, 10, 1)

答案1

得分: 1

我不确定在线课程的作者是如何使用来自df3的数据创建表面图的,因为z需要是一个2D数组(文档可以在这里查看),而df3.iplot(kind='surface',colorscale='rdylbu', x='x', y='y', z='z')不会被Plotly理解,因为它将一个1D数组传递给参数z。也许他们使用的是Plotly的早期版本?

据我所知,这个问题定义不够清晰,因为可以包括那5个点的多个表面图,但为了获得一个表面图,我会为df3z列制作一个可能的2D数组。请注意,只要数组的形状与xy一致,您可以更改传递给z的数组中的任何值,Plotly就能够呈现它。

df3 = pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,20,10],'z':[[5,4,0,0,0],[3,4,0,0,0],[2,2,3,0,0],[1,1,1,2,0],[0,0,0,0,1]]})
df3.iplot(kind='surface', colorscale='rdylbu', x='x', y='y', z='z')

3D曲面图为空

英文:

I am not sure how the author of the online course produced a surface plot using the data from df3 because z needs to be a 2D array (the documentation can be viewed here), and df3.iplot(kind='surface',colorscale='rdylbu', x='x', y='y', z='z') won't be understood by plotly because this passes a 1D array to the parameter z. Perhaps they were using an earlier version of plotly?

As far as I can tell, this question is not well defined because there are multiple surface plots that could include those 5 points, but for the purpose of obtaining a surface plot, I will make up a possible 2D array for the z column of df3. Note that you could change any of the values in the array being passed to z and plotly would be able to render it as long as the shape is consistent with x and y.

df3 = pd.DataFrame({'x':[1,2,3,4,5],'y':[10,20,30,20,10],'z':[[5,4,0,0,0],[3,4,0,0,0],[2,2,3,0,0],[1,1,1,2,0],[0,0,0,0,1]]})
df3.iplot(kind='surface',colorscale='rdylbu', x='x', y='y', z='z')

3D曲面图为空

huangapple
  • 本文由 发表于 2023年2月14日 03:41:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440505.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定