Swawa
Swawa

Reputation: 209

How to change the tick format of a plotly color bar?

I plot a line track over a map using plotly. I add a scale of the used colors. Data range for the ticks are numbers between 0.... 30 000. The ticks are displayed as "5k", "10k", "15k"... instead of "5000", "10000", "15000"... How do I change the ticks format to the latter?

My code:

# Draw a plot of a ground track
import plotly.graph_objects as go

fig = go.Figure(go.Scattermapbox(
    mode = "markers",   
    lon = data.Wgs84Longitude,
    lat = data.Wgs84Latitude,
    marker = {'size': 5, 
              'color':data.Wgs84Altitude, 
              'colorscale': 'viridis', 
              'opacity': 0.5,
              'showscale': True,
              'colorbar': dict(
                  title='Altitude / m',
                  thickness=20,
                  titleside='top',
                  outlinecolor='rgba(68,68,68,0)',
                  ticks='outside',
                  ticklen=3)  }))

fig.update_layout(
    title = "Ground Track",
    title_x=0,
    title_y=0.95,
    width=800, 
    height=700,
    margin ={'l':0,'t':50,'b':0,'r':0},
    mapbox = {
        'center': {'lon': 10, 'lat': 10},
        'style': "stamen-terrain",
        'center': {'lon': Lon, 'lat': Lat},
        'zoom': 8})

fig.show()

enter image description here

Thank you for your help.data

Upvotes: 1

Views: 3084

Answers (1)

Chris Papadimitriou
Chris Papadimitriou

Reputation: 46

You can use the .update_coloraxes method and change the colorbar_tickformat

If you want the plain number you can write:

fig.update_coloraxes(colorbar_tickformat = '.')

If you want to a comma separator you can write:

fig.update_coloraxes(colorbar_tickformat = ',')

Upvotes: 2

Related Questions