plotly / plotly/plotly.py

Allow ticktext for minor ticks

Đang mở
#4,911 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature P3
Ngôn ngữ chính
Python
Star
18.8k
Fork
2.8k
Merge trung bình
16 giờ 26 phút
Pull request đã merge (30 ngày)
21

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu từ điểm vào fig.update_xaxes và cấu hình trục phụ được nêu trong issue. Theo dõi cách các thuộc tính của vạch chia phụ được biểu diễn và truyền qua Python graph-object API. Hoàn thành khi các vạch chia phụ chấp nhận ticktext, ticktextcolor và ticktextfontsize, đồng thời nhãn vạch chia chính được ưu tiên khi các vị trí trùng nhau.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
data-visualization
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.