在可绘制的3D散点图中显示图例和标签轴 [英] Show legend and label axes in plotly 3D scatter plots

查看:269
本文介绍了在可绘制的3D散点图中显示图例和标签轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉让您今天忙于一些棘手的问题.这将是另一个: 如何在plotly的新3D散点图上显示图例和轴标签?

Sorry for keeping you busy with plotly questions today. Here would be another one: How would I show the legend and axes labels on plotly's new 3D scatter plots?

例如,如果我有以下2D散点图,可以使一切正常,那么我添加了另一个尺寸,但是轴标签不再显示(请参见下面的代码),并且图例也出现了同样的问题.有小费吗?谢谢!

E.g., if I have the following scatter plot in 2D that produced everything fine, I added another dimension but the axes labels don't show anymore (see code below), and the same problem with the legend. Any tips? Thanks!

traces = []

for name in ('Iris-setosa', 'Iris-versicolor', 'Iris-virginica'):

    trace = Scatter3d(
        x=Y[y==name,0],
        y=Y[y==name,1],
        z=Y[y==name,2],
        mode='markers',
        name=name,
        marker=Marker(
            size=12,
            line=Line(
                color='rgba(217, 217, 217, 0.14)',
                width=0.5
            ),
            opacity=0.8
        )

    )
    traces.append(trace)


data = Data(traces)
layout = Layout(xaxis=XAxis(title='PC1'),
                yaxis=YAxis(title='PC2'),
                zaxis=ZAxis(title='PC3')
                )
fig = Figure(data=data, layout=layout)
py.iplot(fig)

推荐答案

您将关闭! 3D轴实际上嵌入在Scene对象中.这是一个简单的示例:

You're close! 3D axes are actually embedded in a Scene object. Here is a simple example:

import plotly.plotly as py
from plotly.graph_objs import *

trace1 = Scatter3d(
    x=[1, 2],
    y=[1, 2],
    z=[1, 2],
    name='Legendary'
)
data = Data([trace1])
layout = Layout(
    showlegend=True,
    scene=Scene(
        xaxis=XAxis(title='x axis title'),
        yaxis=YAxis(title='y axis title'),
        zaxis=ZAxis(title='z axis title')
    )
)

FigureWidget(data=data, layout=layout)

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆