首页 > 解决方案 > 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)

数据图像
xy 数据

纤维取向的半极坐标图
纤维取向的半极坐标图

标签: pythonpython-3.xplotly

解决方案


非常感谢 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)

plotly 半极地图


推荐阅读