plotly / plotly/plotly.py

Allow ticktext for minor ticks

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

还没有人认领这个 Issue。

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

描述

Here is the baseline plot :

import plotly.express as px
import pandas as pd
from datetime import timedelta

# Example data
df = pd.DataFrame({
    "Task": ["Task A", "Task B", "Task C"],
    "Start": ["2023-01-01 08:00:00", "2023-01-02 09:30:00", "2023-01-04 11:00:00"],
    "Finish": ["2023-01-01 15:00:00", "2023-01-02 20:00:00", "2023-01-04 19:00:00"],
})

# Create the timeline figure
fig = px.timeline(
    df,
    x_start="Start",
    x_end="Finish",
    y="Task",
    title="Timeline with major and minor ticks on x axis",
)
df['Start'] = pd.to_datetime(df['Start'])
df['Finish'] = pd.to_datetime(df['Finish'])

# Define tick positions and labels
horizon_start = df['Start'].min().replace(hour=0, minute=0)
horizon_end = df['Finish'].max().replace(hour=0, minute=0) + timedelta(days=1)
minor_ticks = pd.date_range(horizon_start, horizon_end, freq="6h")

fig.update_xaxes(
    showgrid=True,
    gridcolor="lightgray",
    gridwidth=2,
    dtick="D1",
    tickformat="%e %b",
    tickangle=-45,
    minor={
        "ticklen": 3,
        "tickcolor": "lightgray",
        "tickmode": "array",
        "showgrid": True,
        "gridwidth": 0.5,
        "tickvals": minor_ticks,
    },
)

# Show the figure
fig.show()

Image

I would like to have the possibility of displaying ticktext for minor ticks + ticktextcolor + ticktextfontsize, with something like :

minor_text = [t.strftime('%Hh').lstrip('0') if t.hour != 0 else "0h" for t in minor_ticks]

fig.update_xaxes(
    (...)
    minor={
        "ticklen": 3,
        "tickcolor": "lightgray",
        "tickmode": "array",
        "showgrid": True,
        "gridwidth": 0.5,
        "tickvals": minor_ticks,
        "ticktext": minor_text,
        "ticktextcolor": 'lightgray',
        "ticktextfontsize": 5,
    },
)

Ideally, for the ticks that are both in major and minor ticks, only the major tick text would be displayed.

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 fig.update_xaxes 入口和 issue 中所示的次要坐标轴配置开始。跟踪次要刻度属性如何表示并通过 Python graph-object API 传递。完成标准是次要刻度接受 ticktext、ticktextcolor 和 ticktextfontsize,并且当位置重叠时,主要刻度标签具有优先级。

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

评估

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

把新 issue 发到你的邮箱

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