plotly / plotly/plotly.py

Cannot increase distance between shape and its label outside of the object

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

まだ誰も着手していません。

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

説明

Challenge

I would like to draw a shape using the label argument to position the label outside of the shape. Unfortunately, the label always touches the shape and padding only works in one direction: towards the center of the shape.

Here is an example:

import plotly.graph_objects as go

fig = go.Figure()

for i in range(0, 4):
    fig.add_shape(
        go.layout.Shape(
            type="rect",
            x0=10,
            y0=10*i + 3,
            x1=15,
            y1=10*i + 10,
            label={
                "text": f"Padding: {i*10}px",
                "textposition": "middle right",
                "xanchor": "left",
                "yanchor": "middle",
                "padding": i*10,
            },
        )
    )

fig.update_layout(xaxis_range=[0, 20], yaxis_range=[0, 60])

fig.show()

Despite seting xanchor="left" and textposition="middle right", the label barely touches the shape (for padding=0) and with increasing padding the label always moves towards the center.

Image

Setting padding to a negative value seems not to be allowed:

ValueError: 
    Invalid value of type 'builtins.int' received for the 'padding' property of layout.shape.label
        Received value: -10

    The 'padding' property is a number and may be specified as:
      - An int or float in the interval [0, inf]

Expected Behavior

Either infer from anchor and textposition, if a label should be outside of the shape, or allow negative values for padding so that I can increase the distance between the rectangle and the label.

I could not find any other info regarding this observation and I would like to avoid using an annotation as a workaround.

Am I overlooking something or is this a bug?

System Info

python: v3.10.11
plotly: v5.24.1

Working in a VSCode (v1.96.2) notebook and tested multiple different renderers with identical outcome: "vscode", "notebook", "browser".
Same result with write_image and pdf and png.

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

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

はじめの一歩

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

調査の方向性

まず、提供されている go.Figure/add_shape の例を、異なる padding 値と renderer で実行します。shape label が textposition、xanchor、padding をどのように扱うかを追跡します。annotation の workaround なしで label を shape の外側に離して配置でき、示されたケースに対するリグレッションカバレッジがある状態になれば、issue は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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