2

There is possibility to isolate trace in legend, but it isolate only markers and not the text on them. How to isolate text as well?

import plotly.express as px
import plotly.graph_objs as go
import pandas as pd

rows=[['501-600','15','122.58333','45.36667'],
      ['till 500','4','12.5','27.5'],
      ['more 1001','41','-115.53333','38.08'],
      ]

colmns=['bins','data','longitude','latitude']
df=pd.DataFrame(data=rows, columns=colmns)
df = df.astype({"data": int})

fig=px.scatter_geo(df,lon='longitude', lat='latitude',
                      color='bins',
                      opacity=0.5,
                      size='data',
                      projection="natural earth", hover_data=(['data']))

fig.add_trace(go.Scattergeo(lon=df["longitude"],
              lat=df["latitude"],
              text=df["data"],
              textposition="middle center",
              mode='text',
              showlegend=False))
fig.show()

If you click on visualization init's legend part on one of the "bins" then the marker of this bin dissapere, but label of it's marker will still be there (see pics below). enter image description here enter image description here

PS I need additional trace for labels, coz in my initial work I put label not for all markers.

Dmitry
  • 361
  • 6
  • 21

0 Answers0