plotly / plotly/plotly.py

Problem with radialaxis ticks in polar plot when using date values

未关闭
#3,481 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P3
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

Hello, I managed to create a polar heatmap plot following the examples given in #2024, but when trying to use time as the radial dimension I found some problems with the ticks. I tried with tickmodes auto, linear and array but got wrong ticks with all of them. The time values shown in the hover are correct, only the ticks appear to be wrong. Does anyone have a suggestion on what may be the problem?
Thank you.

import numpy as np
import pandas as pd
import plotly.graph_objects as go
from plotly.offline import plot

from datetime import datetime, timedelta

# dt_start, dt_end, dt_step ='2000-01-01', '2001-01-01', '1MS'
dt_start, dt_end, dt_step ='2000-01-01', '2000-01-10', '1D'

times = pd.date_range(dt_start, dt_end, freq=dt_step).values

dirs = np.arange(180, 271, 10)

r, theta = np.meshgrid(times, dirs)

z = np.random.random(r.shape)

hovertemplate = (f'date: %{{r|%Y-%m-%d %H:%M:%SZ}}<br>'
                 f'direction: %{{theta}}<br>'
                 f'value: %{{customdata[0]:.2f}}'
                 '<extra></extra>')

fig = go.Figure(go.Barpolar(r=r.ravel(),
                            theta=theta.ravel(),
                            marker_color=z.ravel(),
                            customdata=np.expand_dims(z.ravel(), 0).T,
                            hovertemplate=hovertemplate))

fig.update_layout(polar=dict(
    angularaxis=dict(tickvals=np.arange(0, 360, 45),
                     direction='clockwise'),
    radialaxis=dict(angle=45,
                    tickangle=45,
                    tickfont={'size': 14},
                    tickformat='%Y-%m-%d %H:%M:%S',

                    # tickmode='auto',
                    # nticks=5,

                    # tickmode='linear',
                    # tick0=times[0],
                    # dtick='1D',

                    tickmode='array',
                    tickvals=times,

                    )))

fig.show()

With tickmode='auto':

tickmode_auto

With tickmode='linear':

tickmode_linear

With tickmode='array':

tickmode_array

Using plotly.version = '5.4.0'

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 Plotly 5.4.0 运行提供的 Python 示例,并比较 auto、linear 和 array 模式生成的径向轴刻度。跟踪日期值 r 数据的径向轴刻度处理。完成标准是:三个受支持的模式都能生成位置和格式均正确的日期刻度。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。