6

How to put the legend above/ below the chart and change the font sizes? I have a chart with 12 long legend names. Putting the legend on the right side will compromise the chart.

Also I need the legend names be horizontal. Not all names on the vertical line it will be too long.

1
  • 2
    Did the answer help you? Commented Jan 18, 2017 at 2:43

1 Answer 1

13

You can set the orientation of the legend by via orientation attribute in the legend attribute in the layout settings:

layout = plotly.graph_objs.Layout(
    legend=dict(orientation="h")
)

e.g.

import plotly

layout = dict()
trace1 = plotly.graph_objs.Bar(
    x=['giraffes', 'orangutans', 'monkeys'],
    y=[20, 14, 23],
    name="Stackoverflow's personal zoo without any real name but some really long text"
)
trace2 = plotly.graph_objs.Bar(
    x=['giraffes', 'orangutans', 'monkeys'],
    y=[12, 18, 29],
    name="Another zoo which doesn't have a name but but lots of superfluous characters"
)
trace3 = plotly.graph_objs.Bar(
    x=['giraffes', 'orangutans', 'monkeys'],
    y=[15, 12, 32],
    name="Yet another zoo with plenty of redundant information"
)

data = [trace1, trace2, trace3]
layout = plotly.graph_objs.Layout(
    barmode='group',
    legend=dict(orientation="h")
)

fig = dict(data=data, layout=layout)

plotly.plotly.sign_in('user', 'token')
plot_url = plotly.plotly.plot(fig)

Default legend Default legend Horizontal legend

Horizontal legend

Sign up to request clarification or add additional context in comments.

1 Comment

I am looking for a word wrap alternative

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.