手动更改 plotly scatterpolar 标签

Change plotly scatterpolar labels manually(手动更改 plotly scatterpolar 标签)
本文介绍了手动更改 plotly scatterpolar 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个散点图,但外部的标签以度数而不是方向(N、NE、E 等)显示方向.我的数据是度数,所以我需要手动替换图中显示的标签.我当前的代码是:

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.). My data is in terms of degrees, so I will need to manually replace the labels shown on the 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. Any suggestions to make the plot show the direction instead of degree? Thanks.

注意:数据可以在 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"]
            )
    ))

这篇关于手动更改 plotly scatterpolar 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)