Rename Axes In Plotly 3d Hover Text
I'm drawing a picture in 3D with plot.ly and I want my axes to be referenced as (t, x, y) instead of (x, y, z). It is possible to give them different titles (under Scene object in
Solution 1:
This is more workaround than solution, but you could define a list of strings, one item for each point on your line, where each item in the list is a string of whatever text you wanted to show when hovering (including the string "<br>"
for a line return), then set text=your_list
and hoverinfo="text"
.
Like this:
from plotly.graph_objs import Scatter3d, Layout, Scene
from numpy import sin, cos, linspace, pi
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
t = linspace(0, 4*pi)
your_list=[]
for iter_t in t:
iter_string = 't:'+'%1.3f'%iter_t+'<br>' + 'x:'+'%1.3f'%cos(iter_t) + '<br>'+'y:'+'%1.3f'%sin(iter_t)
your_list.append(iter_string)
trace = Scatter3d(
x = t,
y = cos(t),
z = sin(t),
mode = 'lines',
text=your_list,
hoverinfo='text')
layout = Layout(width = 500, height = 500, scene = Scene(
xaxis = {'title': 't'},
yaxis = {'title': 'x'},
zaxis = {'title': 'y'}))
iplot(dict(data=[trace], layout=layout))
Resulting plot looks like this
You should probably be saving the computed values in the for loop in order to prevent having to compute them more than once, but you get the idea.
Post a Comment for "Rename Axes In Plotly 3d Hover Text"