Horizontal Bar Charts

Following

Horizontal Bar Charts
https:// plot.ly/python/horizontal-bar-charts/

I can’t turn the bar chart and https:// plot.ly/python/table/ into horizontal – I tried to use type='barh', or orientation = 'h', but both failed. Here is a piece of the code:

# Make traces for graph
trace1 = go.Scatter(x=teams, y=GFPG, type='bar', orientation = 'h',
					marker=dict(color='#0099ff'),
					name='Goals For<br>Per Game',
					xaxis='x2', yaxis='y2')
trace2 = go.Scatter(x=teams, y=GAPG, type='bar', orientation = 'h',
					marker=dict(color='#404040'),
					name='Goals Against<br>Per Game',
					xaxis='x2', yaxis='y2')

# Add trace data to figure
data = [trace1, trace2]

# Plot!
fig = go.Figure(data=data) #, layout=layout)
py.iplot(fig, filename='tutorial/bar_plotly_grouped_h')

Full code is at, https:// gist.github.com/suntong/6e3f4cbd8056c699c0d2.

That should be go.Bar not go.Scatter (the example at https://plot.ly/python/table/ has been updated to reflect this)
Then orientation = 'h' should work

Thanks chelsea, yeah, it’s working.

However, there are still two things I still can’t fix myself. Please take a look at the updated https://gist.github.com/suntong/6e3f4cbd8056c699c0d2

The "In [8]" is working, but the yaxis is upside-down, I tried to reverse it myself, like below,

layout = go.Layout(
    yaxis=dict(
        autorange='reversed'
    )
)

But it is not working.

Further, there is no much room to display full y-lables. All my labels are arranged such that the words from the beginning of the label are much more important than the ending. So it is also possible to show the beginning of the label instead of the end of it, if there isn’t enough room to display all.

Please help. Thanks

Taking a look at your example it looks like the axis you want to reverse is actually yaxis2 so you can run

    yaxis2=dict(
        autorange='reversed'
    )
)```

For the other issue I would suggest editing the margins. There's some information on that on our reference page here: https://plot.ly/python/reference/#layout-margin
1 Like