Hi all, Iβm trying to shorten long text labels on the y-axis of a heatmap, where the y-axis has a nested-type structure.
Example:
import numpy as np
import plotly.graph_objects as go
x = ['1','2']
y = np.array(
[
['Veryveryveryveryveryverylong1', 'Veryveryveryveryveryverylong1','short', 'short'],
['A', 'B', 'A', 'B']
]
)
z = np.random.rand(4,2)
fig = go.Figure()
fig.add_trace(go.Heatmap(x=x, y=y, z=z))
What Iβd like, is the Veryveryveryveryveryverylong1
label to be shortened to Veryveryve...
or something (but still displaying the full label via the tooltip).
I tried altering the ticktext
, like
import pandas as pd
y_ser = pd.Series(y[0])
y_0 = np.where(y_ser.str.len() > 10, y_ser.str[:10] + "...", y_ser)
new_y = np.array([y_0, y[1]])
fig.update_layout(
yaxis = {
'tickmode': 'array',
'tickvals': y,
'ticktext': new_y
}
)
(and several options around this) but this just removes the y-axis labels completely.
Very grateful for any suggestions!