Horizontal Legends in Python/v3

How to add images to charts as background images or logos.


Note: this page is part of the documentation for version 3 of Plotly.py, which is not the most recent version.
See our Version 4 Migration Guide for information about how to upgrade.

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

Horizontal Legend

In [1]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np

trace1 = go.Scatter(
                x=np.random.randn(75),
                mode='markers',
                name="Plot1",
                marker=dict(
                size=16,
                color='rgba(152, 0, 0, .8)'
                ))
trace2 = go.Scatter(
                x=np.random.randn(75),
                mode='markers',
                name="Plot2",
                marker=dict(
                size=16,
                color='rgba(0, 152, 0, .8)'
                ))
trace3 = go.Scatter(
                x=np.random.randn(75),
                mode='markers',
                name="Plot3",
                marker=dict(
                size=16,
                color='rgba(0, 0, 152, .8)'
                ))

data = [trace1, trace2, trace3]
layout = go.Layout(
                legend=dict(
                orientation="h")
                )
figure=go.Figure(data=data, layout=layout)

py.iplot(figure)
Out[1]:

Reference

See https://plotly.com/python/reference/#layout-legend-orientation for more information and chart attribute options!