对于图形的纵横比,plotly 中是否有相当于 matplotlib 中 plt.axes('scaled') 的函数?

Mar*_* GN 1 matplotlib plotly-python

我想使用 Plotly express 绘制一些坐标,因为它允许我采用更具交互性的方法,但我找不到以单行中使用 matplotlib.pyplot 进行管理的方式来控制轴中的比例的方法

plt.axis("scaled")
Run Code Online (Sandbox Code Playgroud)

您能分享一些建议吗?谢谢。

这是使用 Plotly Express 的代码:

fig = px.scatter(coordinates_utm, x='EASTING', y='NORTHING', title=name,
                         hover_name=coordinates_utm.index, 
                         hover_data={'NORTHING':':.6f','EASTING': ':.6f'})
    
        fig.add_trace(px.scatter(coordinates_utm_lineal, x='x', y='ylineal',color_discrete_sequence=['red']).data[0])
    
Run Code Online (Sandbox Code Playgroud)

这是使用 plt 的代码:

fig.show()
plt.figure()
plt.scatter(coordinates_utm_lineal.x,coordinates_utm_lineal.ylineal,s=2)
plt.scatter(coordinates_utm.EASTING,coordinates_utm.NORTHING, s=2)
plt.axis("scaled")
plt.show()
Run Code Online (Sandbox Code Playgroud)

这是我当前的输出 在此输入图像描述 在此输入图像描述

Dav*_*_sd 6

遗憾的是,您没有提供完全可重现的示例,因此我将创建自己的示例。

另外,我不太熟悉plt.axis("scaled")我通常使用的plt.axis("equal"). 阅读与 相关的文档plt.axis,它们似乎有些相似。看看下面的回答能否满足您的需求。

import plotly.express as px
import numpy as np
t = np.linspace(0, 2*np.pi)
x = np.cos(t)
y = np.sin(t)

fig = px.scatter(x=x, y=y)
fig.layout.yaxis.scaleanchor="x"
fig.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述