Show Sidebar Hide Sidebar

Horizontal Bar Charts in Pandas

How to make a hortizontal bar chart in Pandas.

# Learn about API authentication here: https://plot.ly/pandas/getting-started
# Find your api_key here: https://plot.ly/settings/api

import pandas as pd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go

N = 20
x = np.linspace(0, 1, N)
y = np.abs(np.random.randn(N))
df = pd.DataFrame({'x': x, 'y': y})
df.head()

data = [
    go.Bar(
        x=df['y'], # assign x as the dataframe column 'x'
        y=df['x'],
        orientation='h',
    )
]

# IPython notebook
# py.iplot(data, filename='pandas-horizontal-bar')

url = py.plot(data, filename='pandas-horizontal-bar')
# Learn about API authentication here: https://plot.ly/pandas/getting-started
# Find your api_key here: https://plot.ly/settings/api
# Cufflinks binds plotly to pandas dataframes in IPython notebook. Read more


import plotly.plotly as py
import cufflinks as cf
import pandas as pd
import numpy as np

cf.set_config_file(offline=False, world_readable=True, theme='ggplot')

df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
df.iplot(kind='barh',barmode='stack', bargap=.1, filename='cufflinks/barh')

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.