【问题标题】:How can I plot an image in Python in 3D?如何在 Python 中绘制 3D 图像?
【发布时间】:2019-07-01 20:50:48
【问题描述】:

使用 Python 将图像插入 2d 图表已得到答复here...如何在 3d 中执行此操作?正在寻找这样的东西(图片来自MATLAB example)...

【问题讨论】:

    标签: python matplotlib 3d plotly


    【解决方案1】:

    我不认为这就是 plotly 设计图像插入的方式,它更多的是在情节中添加背景图像。请参考以下示例,了解使用 layout 对象的 images 属性可以实现的目标。了解更多请阅读here

    import pandas as pd
    import numpy as np
    import plotly.plotly as py
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
    init_notebook_mode(connected=True)
    
    
    
    x, y, z = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
    trace1 = go.Scatter3d(
        x=x,
        y=y,
        z=z,
        mode='markers',
        marker=dict(
            size=12,
            line=dict(
                color='rgba(217, 217, 217, 0.14)',
                width=0.5
            ),
            opacity=0.8
        )
    )
    
    x2, y2, z2 = np.random.multivariate_normal(np.array([0,0,0]), np.eye(3), 200).transpose()
    trace2 = go.Scatter3d(
        x=x2,
        y=y2,
        z=z2,
        mode='markers',
        marker=dict(
            color='rgb(127, 127, 127)',
            size=12,
            symbol='circle',
            line=dict(
                color='rgb(204, 204, 204)',
                width=1
            ),
            opacity=0.9
        )
    )
    data = [trace1, trace2]
    layout = go.Layout(
        margin=dict(
            l=0,
            r=0,
            b=0,
            t=0
        ),
        xaxis= dict(visible = False),
        yaxis= dict(visible = False),
        images= [dict(
                      source= "https://images.plot.ly/language-icons/api-home/python-logo.png",
                      xref= "x",
                      yref= "y",
                      x= 1,
                      y= 3,
                      sizex= 4,
                      sizey= 4,
                      sizing= "stretch",
                      opacity= 0.3,
                      layer= "below")]
    )
    fig = go.Figure(data=data, layout=layout)
    iplot( fig )
    

    【讨论】:

    • 嗯,我无法执行您的代码。这个解决方案是通过旋转图表来改变图像的透视图,还是只是作为 2d 留在背景中?我真的也需要旋转图像
    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 2013-03-09
    • 2021-07-21
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    相关资源
    最近更新 更多