3D Hover Options in Python/v3
How to customize 3d hover options in python with Plotly.
Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Try Plotly Studio now.
See our Version 4 Migration Guide for information about how to upgrade.
New to Plotly?¶
Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
Customize Hover for Spikelines¶
By default, Plotly's 3D plots display lines called "spikelines" while hovering over a point. These lines project from the hover point to each of the three axes' normal planes and then extend from those projection data points to the planes' wall boundaries.
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
data = [go.Scatter3d(
x=np.random.randn(50),
y=np.random.randn(50),
z=np.random.randn(50),
)]
layout = go.Layout(
scene=go.layout.Scene(
xaxis=go.layout.scene.XAxis(
spikecolor='#1fe5bd',
spikesides=False,
spikethickness=6,
),
yaxis=go.layout.scene.YAxis(
spikecolor='#1fe5bd',
spikesides=False,
spikethickness=6,
),
zaxis=go.layout.scene.ZAxis(
spikecolor='#1fe5bd',
spikethickness=6,
),
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='hover-spikelines')
import plotly.plotly as py
import plotly.graph_objs as go
x = [10,20,30,40]
y = [0,1,2,3]
z = [[2,2,2,3],
[1,1,1,1],
[1,1,0,0],
[0,0,0,0]]
data = [go.Surface(
opacity=0.9,
x=x,
y=y,
z=z,
contours=go.surface.Contours(
x=go.surface.contours.X(
highlight=True,
highlightcolor="#41a7b3",
),
y=go.surface.contours.Y(highlight=False),
z=go.surface.contours.Z(highlight=False),
)
)]
layout = go.Layout(
scene=go.layout.Scene(
xaxis = go.layout.scene.XAxis(showspikes=False),
yaxis = go.layout.scene.YAxis(showspikes=False),
zaxis = go.layout.scene.ZAxis(showspikes=False),
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='hover-surface-contours')
Reference¶
See https://plotly.com/python/reference/#layout-scene and https://plotly.com/python/reference/#surface-contours for more information and options!
