Links

Create Horizontal Barchart

Tags: #plotly #chart #horizontalbar #dataviz #snippet #operations #image #html
Author: Florent Ravenel
Learn more on the Plotly doc : https://plotly.com/python/horizontal-bar-charts/

Input

Import library

import plotly.graph_objects as go

Model

Create the plot

fig = go.Figure(
go.Bar(
x=[20, 14, 23],
y=['giraffes', 'orangutans', 'monkeys'],
orientation='h',
text=[20, 14, 23],
)
)
fig.update_layout(
title="Horizontal barchart" ,
plot_bgcolor="#ffffff",
width=1200,
height=800,
margin_pad=10,
xaxis_showticklabels=False,
bargap=0.1, # gap between bars of adjacent location coordinates.
bargroupgap=0.2 # gap between bars of the same location coordinate.
)
config = {'displayModeBar': False}
fig.show(config=config)

Output

Export in PNG and HTML

fig.write_image(output_image, width=1200)
fig.write_html(output_html)

Generate shareable assets

link_image = naas.asset.add(output_image)
link_html = naas.asset.add(output_html, {"inline":True})
#-> Uncomment the line below to remove your assets
# naas.asset.delete(output_image)
# naas.asset.delete(output_html)