我有一个散点图,但外面的标签显示的是度数而不是方向(北、东北、东等)。我的数据是以度为单位的,所以我需要手动替换图上显示的标签。我目前的代码是
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"
)
))
产生了下面的图 有什么建议可以让图上显示方向而不是度数?谢谢。
注:数据可以在以下网址找到 https:/github.commpudilprojectsblobmasterslc.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"]
)
))