如何在图中修改网格尺寸?

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

我有一个X值列表,一个Y值列表,对于每一对(X,Y),我有一个矩阵形式的值Z.

我想在python中使用plotly来表示它,并修改绘制曲面的网格,使x轴比平常大,得到一个矩形的形状。

请考虑以下示例:

import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
x = np.arange(1, 22, 1)
y = np.array([1, 3.1, 5.7, 10, 15, 20])
mean = [0]*21
cov = np.identity(21)
z = np.random.multivariate_normal(mean, cov, 18)
data = [go.Surface(x=x, y=y, z=z)]
py.plot(data)

enter image description here

这里,x和y轴在网格中具有相同的长度,但我希望x轴具有实际长度的两倍。我一直在寻找一种规模参数,但没有找到答案。

python grid plotly surface
1个回答
3
投票

您可以在图的布局中手动设置轴的纵横比:

data = [go.Surface(x=x, y=y, z=z)]

layout = go.Layout(
    scene = go.layout.Scene(
    aspectmode='manual',
    aspectratio=go.layout.scene.Aspectratio(
        x=2, y=1, z=0.5
    ))
)
fig = go.Figure(data=data, layout=layout)

py.plot(fig)

这将X轴设置为Y轴的两倍,Z轴设置为Y轴的一半长度:

Plotly output after fixing aspect ratio

official Plotly examples

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