将轴标题添加到三维曲面打印袖扣和打印

2024-06-26 06:06:29 发布

您现在位置:Python中文网/ 问答频道 /正文

有谁能给我一个提示,如何添加x,y,z轴标题到3曲面图创建plotly&cufflinks?你知道吗

我用的是Python3.7

import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
# Using plotly + cufflinks in offline mode
import cufflinks
cufflinks.go_offline(connected=True)
init_notebook_mode(connected=True)

import pandas as pd
import numpy as np

# creating dataframe with three axes 
df = pd.DataFrame({'x':[1, 2, 3, 4, 5], 
                    'y':[10, 20, 30, 20, 10], 
                    'z':[5, 4, 3, 2, 1]}) 

# colorscale:red(rd), yellow(yl), blue(bu) 
df.iplot(kind ='surface', colorscale ='rdylbu')

有什么建议吗?谢谢。你知道吗


Tags: importtruegodfinitmodeasplotly
1条回答
网友
1楼 · 发布于 2024-06-26 06:06:29

给你:

import plotly
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)
import pandas as pd

# creating dataframe with three axes 
data = pd.DataFrame({'x':[1, 2, 3, 4, 5], 
                    'y':[10, 20, 30, 20, 10], 
                    'z':[5, 4, 3, 2, 1]}) 

data = [
    go.Surface(
        z = data.as_matrix()
    )
]
layout = go.Layout(
    title='My Surface',
    autosize=False,
    width=1000,
    height=600,
    margin=dict(
        l=65,
        r=50,
        b=65,
        t=90
    ),
    scene = {"xaxis":{"title":"my x axis name"},
             "yaxis":{"title":"my pretty y axis name"},
             "zaxis":{"title":"Z AXIS"}}
)
fig = go.Figure(data=data, layout=layout)

plotly.offline.plot(fig)

enter image description here

相关问题 更多 >