简体   繁体   English

如何在Python中以3D方式绘制图像?

[英]How can I plot an image in Python in 3D?

Inserting an image into a 2d chart using Python has been answered here ... how do I do this in 3d? 此处已回答使用Python将图像插入2d图表中的问题……如何在3d中做到这一点? Looking for something like this (image comes from a MATLAB example )... 寻找这样的东西(图像来自MATLAB示例 )...

使用MATLAB在3D图表中绘制的图像

I don't think that's how plotly has designed the image insertion, its more of adding a background image to the plot. 我认为这不是情节设计图像插入的方式,更多的是在情节中添加背景图像。 Please refer the below example of what can be achieved using images property of layout object. 请参考以下示例,使用layout对象的images属性可以实现什么。 To know more read 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 )

情节插入图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM