I am trying to change the colorbar values from decimal to percentage (is there any way of doing this?) Since I did not find a way, I decided to replace them manually with text, as shown in the code. It does not receive an error but the output is the same. What am I missing here?
Thanks!
import plotly.express as px
import pandas as pd
df2 = pd.read_csv(...)
fig = px.scatter_geo(df2, lon="Longitude",
lat="Latitude",
size="Pop2050",
color="Growth rate 2020-50",
color_continuous_scale=[
[0.0, "rgb(12,51,131)"], [0.21, "rgb(242,211,56)"], [1.0, "rgb(217,30,30)"]],
range_color=(-.35, 1.35),
color_continuous_midpoint=0,
projection="natural earth"
)
color_names = ['120%', '100%', '80%', '60%', '40%', '20%', '0%', '-20%']
color_vals = [0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]
fig.update_traces(marker=dict(colorbar=dict(tickmode='array',
tickvals=color_vals,
ticktext=color_names,
lenmode='pixels')
)
)
fig.show()