Show Sidebar Hide Sidebar

3D Bubble Charts in Pandas

How to make 3D Bubble Charts with Pandas and Plotly.

3D Bubble Charts in Pandas

Example with Sizing and Color by Variables from a dataset
In [1]:
import plotly.plotly as py
from plotly.graph_objs import *

import pandas as pd

# Get Data: this ex will only use part of it (i.e. rows 750-1500)
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv')

trace1 = Scatter3d(
    x=df['year'][750:1500],
    y=df['continent'][750:1500],
    z=df['pop'][750:1500],
    text=df['country'][750:1500],
    mode='markers',
    marker=dict(
        sizemode='diameter',
        sizeref=750,
        size=df['gdpPercap'][750:1500],
        color = df['lifeExp'][750:1500],
        colorscale = 'Viridis',
        colorbar = dict(title = 'Life<br>Expectancy'),
        line=dict(color='rgb(140, 140, 170)')
    )
)

data=[trace1]
layout=dict(height=800, width=800, title='Examining Population and Life Expectancy Over Time')
fig=dict(data=data, layout=layout)
py.iplot(fig, filename='3DBubble')
Out[1]:

Reference

Still need help?
Contact Us

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