When I didnt’t set the facet_col_wrap
, the titles are correct:
import plotly.express as px
import xarray as xr
# Load xarray from dataset included in the xarray tutorial
ds = xr.tutorial.open_dataset('eraint_uvz').sel(level=500)
data = ds.to_array().transpose('month', ...)
# fix the bug
# TypeError: %d format: a real number is required, not str
plot_data = data.assign_coords({'variable': range(len(data['variable']))})
fig = px.imshow(plot_data, animation_frame='month',
facet_col='variable', #facet_col_wrap=1,
color_continuous_scale='viridis')
# set variable back to string
# https://community.plotly.com/t/cant-set-strings-as-facet-col-in-px-imshow/60904
for k in range(len(data['variable'])):
fig.layout.annotations[k].update(text = data['variable'].values[k])
fig.show()
However, if I set facet_col_wrap
to one, the titles are wrong.
Note that if I didn’t modify the annotation manually, the titles are correct.