【问题标题】:How do I create a surface graph with pyplot?如何使用 pyplot 创建曲面图?
【发布时间】:2019-11-12 17:05:47
【问题描述】:

我已运行此代码,因为我想将列表中的点映射到曲面图中。但是,虽然通过 Z,y,x 的点的范围仅从 1 到 3,但曲面图的维度之一是 1 到 8。您能帮我解决这个问题吗?

import pandas as pd
import plotly
from plotly import __version__
print (__version__) #This is to know which version of plotly you are running ::Reference: https://www.superdatascience.com/pages/learn-plotly

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objects as go

import numpy as np
z_data = np.array([
    [1,3,3],
    [1,3,3],
    [1,2,2],
    [2,2,2],
    [2,1,2],
    [2,2,2],
    [3,1,1],
    [3,1,1],
    [3,2,1],
    [3,2,2]
])
z_data

【问题讨论】:

    标签: python graph surfaceview surface


    【解决方案1】:

    这是你想要的吗?

    import plotly.graph_objects as go
    import numpy as np
    import pandas as pd
    
    z_data = pd.DataFrame(np.array([
        [1,3,3],
        [1,3,3],
        [1,2,2],
        [2,2,2],
        [2,1,2],
        [2,2,2],
        [3,1,1],
        [3,1,1],
        [3,2,1],
        [3,2,2]
    ]))
    
    fig = go.Figure(data=[go.Surface(z=z_data.values)])
    
    fig.update_layout(title='3D Surface figure', autosize=False,
                      width=500, height=500,
                      margin=dict(l=65, r=50, b=65, t=90),
                      scene=dict(
                            xaxis = dict(range=[0,9],),
                            yaxis = dict(range=[0,9],),
                            zaxis = dict(range=[0,9],)
                      ))
    
    
    fig.show()
    

    图在这里:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-13
      • 1970-01-01
      • 2018-11-22
      • 2015-10-26
      • 1970-01-01
      • 2017-04-01
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多