Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly Python heatmap colorbar orientation

Is there a way to change the orientation of the colorbar in Plotly heatmap? Setting the orientation in the layout does not do anything:

go.Layout(
    legend=dict(
    orientation="h")
)

It doesn't even give me an error message. I have also tried change the orientation in the colorbar directly:

colorbar = dict(
    orientation="h"
                   )

but I get the error message that 'orientation' is not a valid property of 'plotly.graph_objs.heatmap.ColorBar'.

I know how to set the position of the colorbar and I have looked the valid properties of the colorbar but could not find a way to set its orientation. Is this possible?

like image 235
Karim Avatar asked Oct 18 '25 14:10

Karim


2 Answers

Set the orientation of the colorbar.

As per the Plotly Documentation:

# For the vertical orintation
fig.update_traces(colorbar_orientation='v', selector=dict(type='heatmap'))

# For the horizontal orintation
fig.update_traces(colorbar_orientation='h', selector=dict(type='heatmap'))

Default: "v" #vertical

like image 152
NILESH KUMAR Avatar answered Oct 20 '25 04:10

NILESH KUMAR


I don't believe so. According to this open issue and the response from Chriddyp (co-founder of Plotly), a horizontal colorbar has not been implemented but this feature may be added in future releases of Plotly.

If you really need it— I suppose you can try to draw the colorbar yourself using annotations but that's admittedly a lot of work.

like image 35
Derek O Avatar answered Oct 20 '25 05:10

Derek O



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!