使坐标轴在 3D 图表中可见

问题描述 投票:0回答:1

我在使轴在 3D 图表中可见时遇到问题。我认为

fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
应该这样做,但它没有任何效果,看起来我错过了一些东西。 此外,我想显示轴的箭头。

import plotly.express as px
import numpy as np
import sys 
from random import randint as rint
import pandas as pd

headers = ("Rank", "GMV", "Inventory", "Categories", "ETRS")
sellers = [(rint(20, 100), rint(500, 10000), rint(10, 200), rint(1, 6), rint(0, 1) == 1) \
           for _ in range(100)]

df = pd.DataFrame(sellers, columns=headers)

fig = px.scatter_3d(df, x='Inventory', y='Rank', z='GMV', size='Categories', color='ETRS')
                        
fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
fig.show()

enter image description here

python-3.x 3d plotly
1个回答
0
投票

3D 图形的轴在场景中设置。添加了带有字符串注释的箭头,但效果不佳。请参阅此参考资料

import plotly.express as px
import numpy as np
import sys 
from random import randint as rint
import pandas as pd

headers = ("Rank", "GMV", "Inventory", "Categories", "ETRS")
sellers = [(rint(20, 100), rint(500, 10000), rint(10, 200), rint(1, 6), rint(0, 1) == 1) \
           for _ in range(100)]

df = pd.DataFrame(sellers, columns=headers)

fig = px.scatter_3d(df, x='Inventory', y='Rank', z='GMV', size='Categories', color='ETRS')
                        
fig.update_layout(
    scene=dict(
        xaxis=dict(showline=True, linewidth=3, linecolor='black'),
        annotations=[
            dict(
                x=0,
                y=100,
                z=0,
                text='>',
                textangle=-45,
                xanchor='left',
                xshift=0,
                # ax=-10,
                # ay=150,
                showarrow=False,
                # arrowcolor='black',
                # arrowsize=1,
                # arrowwidth=2,
                # arrowhead=1
            )
        ]
    ))
fig.update_layout(height=600, margin=dict(t=0))
fig.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.