gpt4 book ai didi

python - 离线绘图忽略plotly python API中的布局参数

转载 作者:行者123 更新时间:2023-11-30 22:58:33 25 4
gpt4 key购买 nike

我正在制作一个 3D 曲面图,取得了中等成功,但有些参数不响应我的标志,例如轴范围、标签和对数刻度,但有些参数会响应,例如整体标题和纵横比。我无法理解这个问题,有人能看到我做错了什么吗?

谢谢

def make3dPlot(surfaceMatrix, regionStart, regionEnd):
data = [go.Surface(z=surfaceMatrix)]
#data = [go.Surface(z=[[1, 2, 3, 4, 9],[4, 1, 3, 7, 9],[5, 4, 7, 2, 9]])]
layout = go.Layout(
title=args.i,
autosize=True,
width=1600,
height=1000,
yaxis=dict(
title='Particle Size',
titlefont=dict(
family='Arial, sans-serif',
size=18,
color='lightgrey'
),
type='log',
autorange=True,
#range=[regionStart, RegionEnd]
),
xaxis=dict(
title="Genomic Co-ordinates",
titlefont=dict(
family='Arial, sans-serif',
size=18,
color='lightgrey'
),
#type='log',
#autorange=False,
range=[10, 15]#regionStart, regionEnd]
),
scene=dict(
aspectratio=dict(x=3, y=1, z=1),
aspectmode = 'manual'
)
)
fig = go.Figure(data=data, layout=layout)


plotly.offline.plot(fig)

使用模拟数据,它看起来像这样,轴不变且没有标签:

plotly example

最佳答案

根据 docs plotly 中 3D 绘图的 xaxisyaxiszaxisScene 的一部分,而不是 Layout.

示例:

from plotly.offline import iplot, init_notebook_mode
import numpy as np
from plotly.graph_objs import Surface, Layout, Scene
init_notebook_mode()

x, y = np.mgrid[-2*np.pi:2*np.pi:300j, -2:2:300j]
surface = Surface(
x=x, y=y, z=-np.cos(x)+y**2/2
)

iplot([surface])

layout = Layout(scene=Scene(xaxis=dict(range=[-1,1])))
iplot(dict(data=[surface], layout=layout))

Screenshot

另请参阅this question .

关于python - 离线绘图忽略plotly python API中的布局参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com