手动更改plotly scatterpolar标签

2024-04-26 17:22:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个散极图,但外面的标签显示的方向是度,而不是方向(N、NE、E等)。我的数据以度为单位,因此我需要手动替换绘图上显示的标签。我目前的代码是:

import pandas as pd
import plotly.graph_objs as go

# Get data
url = "https://raw.githubusercontent.com/mpudil/projects/master/slc.csv"
df = pd.read_csv(url)

fig = go.Figure(data=
    go.Scatterpolar(
        r = list(df['distance']),
        theta = list(df['bearing']),
        mode = 'markers',   
        name = 'log'
    ))

fig.update_layout(
    polar = dict(
      radialaxis = dict(type = "log", tickangle = 45),
      angularaxis = dict(
            thetaunit = "degrees",
            dtick = 45,
            rotation=90,
            direction = "clockwise" 
            )
    ))

这就产生了下面的情节。有什么建议可以让绘图显示方向而不是程度?谢谢

enter image description here

注:数据可在https://github.com/mpudil/projects/blob/master/slc.csv找到


Tags: csv数据httpsimportcomurlgo绘图
1条回答
网友
1楼 · 发布于 2024-04-26 17:22:38

不确定是否有更好的方法,但以下方法应该有效

fig.update_layout(
    polar = dict(
      radialaxis = dict(type = "log", tickangle = 45),
      angularaxis = dict(
            thetaunit = "degrees",
            dtick = 45,
            rotation=90,
            direction = "clockwise",
            tickmode="array",
            tickvals=[0, 45, 90, 135, 180, 225, 270, 315],
            ticktext=["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
            )
    ))

相关问题 更多 >