plotly / plotly/plotly.py

Tick texts on the histogram are shifted to the left if "xbins" and "tickvals" were customized

オープン
#3,780 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@archmoj がすでに取り組んでいます。

2024年7月4日 から。

bug P3
主要言語
Python
スター
18.8k
フォーク
2.8k
平均マージ
16時間 26分
マージ済み PR(30日)
21

説明

Let's build a histogram for 1000 random values from 0 to 1, narrow down the bins and add tick text to each bin. To make the existence of the bug visible, draw a vertical line in the middle of each bin.

import sys
sys.dont_write_bytecode = True
import numpy as np
import pandas as pd
import plotly.express as px

df = pd.DataFrame({'rand_vals': np.random.rand(1, 1000)[0]}).round(4)
hist = px.histogram(df)
hist.update_traces(xbins={'start': df['rand_vals'].min(),
                          'size': 0.01})
ranges = [[round(val, 4),
           round(val + 0.0099, 4)] for val in np.arange(df['rand_vals'].min(),
                                                        df['rand_vals'].max() + 0.01, 0.01)]
hist.update_xaxes(tickvals=[np.mean(rng) for rng in ranges],
                  ticktext=[' - '.join(map(str, rng)) for rng in ranges],
                  tickfont_size=10,
                  rangemode='tozero')
for rng in ranges:
        hist.add_vline(np.mean(rng),
                       line_width=1,
                       line_dash='dash')
hist.show()

Result:
plotly_ticktext_shift_1

An interesting detail: if I double zoom the diagram (HTML), the offset eliminates:
plotly_ticktext_shift_2

If anyone thinks the problem is because the tick texts are too long, let's simplify them by removing ticktext=[' - '.join(map(str, rng)) for rng in ranges],. The displacement will remain:
plotly_ticktext_shift_3

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。