如何从 Plotly 等高线图中提取等高线的 XY 点?

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

我想使用它生成的等高线图来量化图像中的特征。 Plotly 不提供如何计算等值线的详细信息。谁能告诉我如何从这个基本示例中提取该信息?

import plotly.graph_objects as go

fig = go.Figure(data =
    go.Contour(
        z=[[10, 10.625, 12.5, 15.625, 20],
           [5.625, 6.25, 8.125, 11.25, 15.625],
           [2.5, 3.125, 5., 8.125, 12.5],
           [0.625, 1.25, 3.125, 6.25, 10.625],
           [0, 0.625, 2.5, 5.625, 10]]
    ))
fig.show()
python plotly contour plotly-python
1个回答
0
投票

以下是您的示例的操作方法:

import plotly.graph_objects as go

fig = go.Figure(data =
    go.Contour(
        z=[[10, 10.625, 12.5, 15.625, 20],
           [5.625, 6.25, 8.125, 11.25, 15.625],
           [2.5, 3.125, 5., 8.125, 12.5],
           [0.625, 1.25, 3.125, 6.25, 10.625],
           [0, 0.625, 2.5, 5.625, 10]]
    ))
fig.show()

# Extracting contour data
contour_data = fig.data[0].contours

# Accessing XY points of the contours
x_contour = contour_data.x
y_contour = contour_data.y

print("X Contour Points:", x_contour)
print("Y Contour Points:", y_contour)

在这段代码中,我首先像您一样创建等高线图。然后,使用

fig.data[0].contours
提取轮廓数据,最后分别使用
contour_data.x
contour_data.y
访问轮廓的 X 和 Y 点。

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