Reputation: 1716
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.
Upvotes: 6
Views: 23116
Reputation: 31649
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 Horizontal legend
Upvotes: 13