简体   繁体   English

手动更改 plotly scatterpolar 标签

[英]Change plotly scatterpolar labels manually

I have a scatterpolar plot, but the labels on the outside show the direction in terms of degrees rather than directions (N, NE, E, etc.).我有一个 scatterpolar plot,但外面的标签以度数而不是方向(N、NE、E 等)显示方向。 My data is in terms of degrees, so I will need to manually replace the labels shown on the plot.我的数据是度数,所以我需要手动替换 plot 上显示的标签。 My current code is:我目前的代码是:

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" 
            )
    ))

Which produces the plot below.它产生下面的 plot。 Any suggestions to make the plot show the direction instead of degree?有什么建议可以让 plot 显示方向而不是度数? Thanks.谢谢。

在此处输入图像描述

Note: The data can be found at https://github.com/mpudil/projects/blob/master/slc.csv注:数据可以在https://github.com/mpudil/projects/blob/master/slc.csv

Not sure if there is a better way but the following should work不确定是否有更好的方法,但以下应该有效

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"]
            )
    ))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM