Rotating color bar title?

Hello,

I have a few colorbars for my plot each with titles beside them (as in the example image below):

Is there any way to ‘flip’ the color bar title text so that it is rotated 180 degrees? In this example, I want the “E” in “Expression” to be the first letter in the text. reading from top to bottom.

Thanks!

Hi @austinv11 welcome to the forums.

Unfortunately there is no builtin function for this, you would have to use annotations. An example:

import plotly.express as px
import numpy as np

fig = px.imshow(
    np.random.randint(0, 255, size=(10, 10)),
    color_continuous_scale='viridis',
)
fig.update_layout(
    width=600,
    height=600,
    coloraxis_colorbar={"title": 'Real title'}
)

# add your rotated title via annotations
fig.update_layout(
    margin=dict(r=150),
    # ^^ making a bit of space for the annotation
    annotations=[
        dict(
            text="Your title",
            font_size=20,
            font_family='arial',
            font_color='red',
            textangle=90,
            showarrow=False,
            # ^^ appearance
            xref="paper",
            yref="paper",
            x=1.35,
            y=0.5,
            # ^^ position
        )
    ]
)

creates:

1 Like