Hi,
I’m using Scatter3d to create a Network Gragh, and there are a lot nodes in the graph.
If I use ‘mode = markers + text’, the Network Graph will full of text that you can’t see the structure of the graph.
So I want some of the key markers to display text, and others don’t, is there any way can do this?
Your reply would be appreciated!
Set text
to be a list and use None
for the text that you don’t want to display, i.e. instead of text: ['a', 'b', 'c', 'd' ,'e']
, do text: ['a', None, None, None, 'e']
But I still need the text that don’t display to show in the label or somewhere else when I hover on the node. Just use ‘None’ for the text will overwrite the content. Thank you!
Ah OK. Then you can use a combination of the text
property and the hovertext
property:
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(id='graph', figure={
'data': [{
'x': [1, 2, 3],
'y': [1, 1, 1],
'text': ['a', None, 'b'],
'hovertext': ['x', 'y', 'z'],
'mode': 'markers+text',
'textposition': 'top'
}]
})
])
if __name__ == '__main__':
app.run_server(debug=True)
Alternatively, use annotations: https://plot.ly/python/text-and-annotations/#adding-hover-text-to-data-in-line-and-scatter-plots
Thanks again Chris! That solved my problem.![:grinning: :grinning:](https://emoji.discourse-cdn.com/twitter/grinning.png?v=5)
1 Like
Sorry to bother you again Chris, your suggestion worked, but something goes wrong with the node. Instead of displaying nothing, my nodes display a text ‘null’ on them. Here is part of my codes:
import plotly.graph_objs as go
go.Scatter3d(
x=Xn,
y=Yn,
z=Zn,
mode='markers+text',
name='process',
marker = {
'size': group,
'line': {'width':0.5, 'color': 'rgb(50,50,50)'},
'symbol': 'circle',
'color': group,
'colorscale': 'Portland'
},
text=labels_text, # labels_text is a list.
hovertext = labels_hover, # labels_hover is a list. And elements in the list is the text I want display on hover.
hoverinfo='text'
)
And my graph looks like that:
![exam](https://us1.discourse-cdn.com/flex020/uploads/plot/original/2X/f/ffe9caa4486239f7eba9b33c625c89c4e06d060f.png)
How to make those ‘null’ disappear?
I find a way to solve the ‘null’ problem, instead of using None
for the text that I don’t want to display, just use ‘’ (a null string) in the list, now the problem is totally solved~ ![:smiley: :smiley:](https://emoji.discourse-cdn.com/twitter/smiley.png?v=5)
1 Like