【问题标题】:How to change the tick format of a plotly color bar?如何更改绘图彩条的刻度格式?
【发布时间】:2022-10-24 22:10:41
【问题描述】:

我使用 plotly 在地图上绘制线轨迹。我添加了使用颜色的比例。刻度的数据范围是 0.... 30 000 之间的数字。 刻度显示为“5k”、“10k”、“15k”……而不是“5000”、“10000”、“15000”…… 如何将刻度格式更改为后者?

我的代码:

# 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()

谢谢你的帮助。数据

【问题讨论】:

    标签: python-3.x plotly-python colorbar


    【解决方案1】:

    您可以使用.update_coloraxes 方法并更改colorbar_tickformat

    如果你想要纯数字,你可以写:

    fig.update_coloraxes(colorbar_tickformat = '.')
    

    如果你想要一个逗号分隔符,你可以写:

    fig.update_coloraxes(colorbar_tickformat = ',')
    

    【讨论】:

      猜你喜欢
      • 2020-08-03
      • 2022-01-02
      • 2013-10-22
      • 2022-08-11
      • 2020-06-12
      • 1970-01-01
      • 2020-05-29
      • 2017-06-03
      相关资源
      最近更新 更多