plotly / plotly/plotly.py

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

Abierto
#5,157 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug P2
Lenguaje dominante
Python
Estrellas
18.8k
Forks
2.8k
Merge medio
16 h 26 min
PR fusionados (30 d)
21

Descripción

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()

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Ejecuta la reproducción de Python proporcionada con go.Surface y compara su comportamiento de hovertemplate con el ejemplo funcional de go.Scatter3d. Comienza rastreando cómo go.Surface gestiona text y customdata para la salida del hover. La tarea está terminada cuando la etiqueta de hover de la surface muestra el texto definido por el usuario o customdata en lugar del marcador de posición literal %{text}.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
numpy, python
Área
data-visualization
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.