Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 2.18 KB

Plotly_Create_Horizontal_Barchart.md

File metadata and controls

66 lines (47 loc) · 2.18 KB



Template request | Bug report | Generate Data Product

Tags: #plotly #chart #horizontalbar #dataviz #snippet #operations #image #html

Author: Florent Ravenel

Description: This notebook provides instructions on how to create a horizontal bar chart using Plotly.

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)