python - 手动更改散点图标签

标签 python plotly

我有一个散点极坐标图,但外部的标签以度数而不是方向(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" 
            )
    ))

这会产生下面的图。有什么建议可以让 plotly 显示方向而不是程度吗?谢谢。

enter image description here

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

最佳答案

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

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

关于python - 手动更改散点图标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62184046/

相关文章:

python - 验证时读取文件后,具有 FileField 的 Django 模型管理员无法读取 save_model 中的文件

python - 将图形旋转至经纬度

python - 所有参数应该有相同的长度 plotly

python - 在 plotly 中绘制分组的 pandas 数据

python - 可以自动滚动的破折号表

r - Shiny 更新点击点以突出显示它

字典理解中的 Python 作用域

python - 使用连字符重新格式化日期字符串

Python/ flask 错误 : "ImportError: cannot import name _compare_digest"

python - 使用 einsum 对 numpy 进行进一步优化以进行堆叠矩阵向量乘法