Show Sidebar Hide Sidebar

Add Logos to Charts in Python

How to add images as logos to Plotly charts.

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!

Formatting and Positioning Images as Logos

In [2]:
import plotly.plotly as py
import plotly.graph_objs as go

data = Data([
    go.Bar(
        x=['-35.3', '-15.9', '-15.8', '-15.6', '-11.1',
           '-9.6', '-9.2', '-3.5', '-1.9', '-0.9',
           '1.0', '1.4', '1.7', '2.0', '2.8', '6.2',
           '8.1', '8.5', '8.5', '8.6', '11.4', '12.5',
           '13.3', '13.7', '14.4', '17.5', '17.7',
           '18.9', '25.1', '28.9', '41.4'],
        y=['Designers, musicians, artists, etc.',
           'Secretaries and administrative assistants',
           'Waiters and servers', 'Archivists, curators, and librarians',
           'Sales and related', 'Childcare workers, home car workers, etc.',
           'Food preparation occupations', 'Janitors, maids, etc.',
           'Healthcare technicians, assistants. and aides',
           'Counselors, social and religious workers',
           'Physical, life and social scientists', 'Construction',
           'Factory assembly workers', 'Machinists, repairmen, etc.',
           'Media and communications workers', 'Teachers',
           'Mechanics, repairmen, etc.', 'Financial analysts and advisers',
           'Farming, fishing and forestry workers',
           'Truck drivers, heavy equipment operator, etc.','Accountants and auditors',
           'Human resources, management analysts, etc.', 'Managers',
           'Lawyers and judges', 'Engineers, architects and surveyors',
           'Nurses', 'Legal support workers',
           'Computer programmers and system admin.', 'Police officers and firefighters',
           'Chief executives', 'Doctors, dentists and surgeons'],
        marker=dict(
            color='rgb(253, 240, 54)',
            line=dict(color='rgb(0, 0, 0)',
                      width=2)
        ),
        orientation='h',
    )
])

layout = go.Layout(
    images=[dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
        xref="paper", yref="paper",
        x=1, y=1.05,
        sizex=0.2, sizey=0.2,
        xanchor="right", yanchor="bottom"
      )],
    autosize=False, height=800, width=700,
    bargap=0.15, bargroupgap=0.1,
    barmode='stack', hovermode='x',
    margin=dict(r=20, l=300,
                  b=75, t=125),
    title='Moving Up, Moving Down<br><i>Percentile change in income between childhood and adulthood</i>',
    xaxis=dict(
        autotick=False, dtick=10, nticks=0,
        gridcolor='rgba(102, 102, 102, 0.4)',
        linecolor='#000', linewidth=1,
        mirror=True,
        showticklabels=True, tick0=0, tickwidth=1,
        title='<i>Change in percentile</i>',
    ),
    yaxis=dict(
        anchor='x', autotick=False,
        gridcolor='rgba(102, 102, 102, 0.4)', gridwidth=1,
        linecolor='#000', linewidth=1,
        mirror=True, showgrid=False,
        showline=True, zeroline=False,
        showticklabels=True, tick0=0,
        type='category',
    )
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
Out[2]:
In [3]:
import plotly.plotly as py

fig = py.get_figure('https://plot.ly/~Dreamshot/8152/')

fig.layout.images = [dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/accuweather.jpeg",
        xref="paper", yref="paper",
        x=0.1, y=1.05,
        sizex=0.4, sizey=0.4,
        xanchor="center", yanchor="bottom"
      )]

py.iplot(fig, fileopt='overwrite', filename='Logos/Florida_Rainfall_AccuWeather')
Out[3]:
In [4]:
import plotly.plotly as py

fig = py.get_figure('https://plot.ly/~Dreamshot/8160/')

fig.layout.images = [dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/bleacherreport.png",
        xref="paper", yref="paper",
        x=0.5, y=-0.35,
        sizex=0.3, sizey=0.3,
        xanchor="center", yanchor="top"
      )]

py.iplot(fig, fileopt='overwrite', filename='Logos/Top_Earners_BleacherReport')
Out[4]:
In [5]:
import plotly.plotly as py

fig = py.get_figure('https://plot.ly/~Dreamshot/8158/')

fig.layout.images = [dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/theverge.png",
        xref="paper", yref="paper",
        x=0.1, y=1.0,
        sizex=0.2, sizey=0.3,
        xanchor="center", yanchor="bottom"
      )]

fig.layout.legend.orientation = 'h'

py.iplot(fig, fileopt='overwrite', filename='Logos/Apple_Labor_Violations_TheVerge')
Out[5]:
In [6]:
import plotly.plotly as py

fig = py.get_figure('https://plot.ly/~Dreamshot/8155/')

fig.layout.images = [dict(
        source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/politico.png",
        xref="paper", yref="paper",
        x=0.1, y=-0.2,
        sizex=0.4, sizey=0.4,
        xanchor="center", yanchor="bottom"
      )]

py.iplot(fig, fileopt='overwrite', filename='Logos/Foreign_Policy_Politico')
Out[6]:

Reference

See https://plot.ly/python/images/ for more examples of adding images
and https://plot.ly/python/reference/#layout-images for more information and chart attribute options!

Still need help?
Contact Us

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