python - plotly,半极坐标图,将角轴设置为 -90° 到 90°
问题描述
我正在尝试用 python 绘制一个极坐标图,并在二维图像中显示纤维的方向(参见下面的代码)。如果您能告诉我如何更改角轴(当前范围从 0° 到 360°)以匹配我从 -90° 到 90° 的数据,那就太好了。下面是半极坐标图的示例图像、我的数据格式和我的代码。
import plotly.graph_objs as go
from plotly import plotly
import plotly.offline as offline
import numpy as np
# data
x= np.genfromtxt(see data image)
y= np.genfromtxt(see data image)
trace = [
go.Scatterpolar(
r = [y], #radial coordinates
theta = [x], #angular coordinates
mode = 'markers',
marker = dict(
color = 'peru'
)
)
]
layout = go.Layout(
showlegend = True,
polar = dict(
domain = dict( # set chart size and position
x = [0, 0.8],
y = [0.3, 0.8]),
sector = [0, 180], # set chart shape (half or full)
angularaxis = dict(
thetaunit = "degrees",
dtick = 10),
radialaxis = dict(
range = [1, 8000])
))
fig = go.Figure(data=trace, layout=layout)
offline.plot(fig)
解决方案
非常感谢 DatHydroGuy!我用您的更改完全重写了代码,它现在可以工作了。下面是代码和输出的图像。诺斯!再次感谢 HydroGuy,为您提供帮助!
如果有人知道如何旋转它(逆时针旋转 90°)并镜像它(左 -90,上 0,右 90),请告诉我。我尝试rotation=
了direction=
命令,但它们不起作用并与sector=
将角轴范围设置为 -90 到 90 的命令发生冲突。
干杯,罗恩
import plotly.graph_objs as go
from plotly import plotly
import plotly.offline as offline
import numpy as np
import plotly
# data
x= np.genfromtxt("data.csv", delimiter=",", usecols=(0), skip_header=1, encoding = 'unicode_escape')
y= np.genfromtxt("data.csv", delimiter=",", usecols=(1), skip_header=1, encoding = 'unicode_escape')
trace = [
go.Scatterpolar(
r = [float(a) for a in y], #radial coordinates
theta = [float(b) for b in x], #angular coordinates
mode = 'lines',
marker = dict(
color = 'peru'
)
)
]
layout = go.Layout(
showlegend = True,
legend=dict(
x=1),
polar = dict(
domain = dict( # set chart size and position
x = [0, 1],
y = [0, 1]),
sector = [-90,90], # set chart shape (half or full)
angularaxis = dict(
thetaunit = "degrees",
dtick = 10,
#rotation = -90, #does not work
#direction = "clockwise" # does not work
),
radialaxis = dict(
range = [1, 6500])
))
fig = go.Figure(data=trace, layout=layout)
offline.plot(fig)
推荐阅读
- python - 如何将位于文件中的列表转换为我可以在 python 中使用的列表?
- javascript - 使用 JQuery 按类删除重复元素
- javascript - React 获取组件的高度
- html - 如何让绝对定位的元素在父 div 之外可见
- selenium - 无法在 chrome 浏览器的设置弹出窗口中找到 Web 元素
- json - 如何在 Google 表格中写入我的 Firebase 数据?
- django - 更新在 django orm 中不起作用,我的代码有问题吗?
- c++ - std::forward() 的右值引用重载的目的是什么?
- javascript - 如何使用 AJAX 请求将数据从 Javascript 发送到 Python Flask 应用程序?
- ios - 如何使 UIFont 符合可解码