How to make some of markers display text, and others don't?


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__':

Alternatively, use annotations:


Thanks again Chris! That solved my problem.:grinning:


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

                    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.

And my graph looks like that:

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: