Changing format of Plotly axis and ColorBar numbers and hovers

2 questions:
-1- How* do I set the number format anf hover format for a ColorBar/ColorScale on a Scatter? I can set the number and hover formats for the x-axis and y-axis, but not the ColorBar.

  • -2- How do I set the number and hover formats for the x, y, z axes on a Scatter_3d? The commands that work on a 2d scatter don’t seem to work on a 3d scatter.
    Code to demo the problem listed below…
#--------------------------------------------------------------------------------------
import numpy as np
import pandas as pd
import plotly.express as px

df = pd.DataFrame(np.random.random((10,10)), columns=list('abcdefghij'))
print(df)
# How to get ColorScale numbers to show as %, like x and y axes?
# How to get ColorScale Hover Format to show as %, like it does for x and y axes hovers?
fig = px.scatter(df, x = 'a', y = 'b', color = 'd')
fig.update_xaxes(tickformat = ',.1%', hoverformat = ',.1%')
fig.update_yaxes(tickformat = ',.1%', hoverformat = ',.1%')
fig.update_traces(marker_colorbar_tickformat = ',.1%')
fig.show()

# How to change format of x and y axes numbers on 3d Scatter?
# Why is there no fig.update_zaxes property?
fig = px.scatter_3d(df, x = 'a', y = 'b', z = 'c', color = 'd')
fig.update_xaxes(tickformat = ',.1%', hoverformat = ',.1%')
fig.update_yaxes(tickformat = ',.1%', hoverformat = ',.1%')
fig.update_traces(marker_colorbar_tickformat = ',.1%')
fig.show()

for the 3d axes, the axes are under the scene, see for example the first example of https://plot.ly/python/3d-axes/

So you should do

fig.update_layout(scene=dict(xaxis=dict(tickformat=...)))

etc

1 Like

Thankyou! - “scene” worked perfectly
Phil