我想用下面的代码通过Ploly制作一张我所在城市的白天长度饼图:
import typing as t
import plotly.graph_objects as go
def add_circular_labels(fig: go.Figure,
labels: t.List[str]):
fig.add_trace(go.Scatterpolar())
fig.update_layout(
polar = dict(
radialaxis_visible=False,
angularaxis = dict(
type="category",
categoryarray=labels,
direction="clockwise",
showticklabels=True,
ticks="outside",
ticklen=8,
tickcolor="white",
showgrid=False)
)
)
return fig
def main():
values = [0.258, 0.542, 0.201]
labels = ["night-sunrise", "day", "night-sunset"]
sunset, sunrise = "06:11", "19:11"
fig = go.Figure(data=[go.Pie(labels=labels,
values=values,
hole=.7,
direction="clockwise",
sort=False)])
fig.update_layout(template="plotly_dark")
fig.update_traces(marker=dict(colors=["#7D8491", "#DEB841", "#7D8491"]))
fig = add_circular_labels(fig, [f"{i:02d}:00" for i in range(24)])
fig.show()
if __name__ == "__main__":
main()
I want to add two lines to the pie chart, where the grey part meets the golden part, and add labels to them with sunset
and sunrise
, respectively. In short, I would like to see something like this:
我如何才能做到这一点(如果这是可能的话)?