plotly / plotly/plotly.py

Bug Report: hovertemplate in go.Surface doesn't work properly

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

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

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

説明

The hovertemplate for go.Surface doesn't work properly, it can't display the user defined customdata nor 'text', it will only display the plain text as "cost: %{text}".
Of course, I have also tried that it works well for go.Scatter and go. Scatter3d.

Check the following code, you can see the bug:

import plotly.graph_objects as go
import numpy as np

# Example data for the trajectory
x_traj = [0, 1, 2, 3, 4, 5]  # X-coordinates
y_traj = [0, 1, 4, 9, 16, 25]  # Y-coordinates
z_traj = [0, 1, 8, 27, 64, 125]  # Z-coordinates

# Example data for the contour
x = np.linspace(-10, 10, 100)
y = np.linspace(-10, 10, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(np.sqrt(X**2 + Y**2))  # Example Z values

# Create a 3D plot
fig = go.Figure()

# Add the 3D trajectory
fig.add_trace(go.Scatter3d(
    x=x_traj,
    y=y_traj,
    z=z_traj,
    text=[1,2,3,4,5,6],
    mode='lines+markers',  # Use 'lines' for trajectory and 'markers' for points
    line=dict(color='blue', width=2),  # Customize line color and width
    marker=dict(size=5, color='red'),  # Customize marker size and color
    hovertemplate="x: %{x:.2f}<br>y: %{y:.2f}<br>index: %{text}<br> <extra></extra>",
))

# Add the contour on Z=5 plane
fig.add_trace(go.Surface(
    x=x,
    y=y,
    z=np.full_like(Z, 5),  # Set Z=5 for the contour plane
    surfacecolor=Z,  # Use Z values for the contour colors
    text=Z,
    colorscale="Viridis",
    showscale=True,
    contours=dict(
        z=dict(
            show=True,
            start=-1,  # Minimum contour value
            end=1,     # Maximum contour value
            size=0.2,  # Step size between contours
            usecolormap=True,
            project_z=True  # Project contours onto the Z plane
        )
    ),
    opacity=0.7,  # Make the contour plane semi-transparent
    # hoverinfo="x+y+text", # works well
    hovertemplate="x: %{x:.2f}<br>y: %{y:.2f}<br>cost: %{text}<br> <extra></extra>", # doesn't work

))

# Update layout for better visualization
fig.update_layout(
    title="3D Trajectory with Contour on Z=5 Plane",
    scene=dict(
        xaxis_title="X Axis",
        yaxis_title="Y Axis",
        zaxis_title="Z Axis"
    ),
    width=800,
    height=600
)

# Show the plot
fig.show()

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

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

はじめの一歩

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

調査の方向性

提供された Python の再現コードを go.Surface で実行し、その hovertemplate の動作を、動作している go.Scatter3d の例と比較します。まず、go.Surface が hover 出力のために text と customdata をどのように処理しているかを追跡します。surface の hover ラベルが、リテラルな %{text} プレースホルダーではなく、ユーザー定義のテキストまたは customdata を表示すれば完了です。

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

評価

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

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

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