Back to Modin

Demonstrating Plotly Modin Interoperability

examples/jupyter/integrations/plotly.ipynb

0.37.13.7 KB
Original Source

Demonstrating Plotly Modin Interoperability

Currently Plotly is not completely interoperable with Modin. Each visualization is created with a Modin and then pandas dataframe for comparison.

python
import modin.pandas as pd
import pandas
import numpy as np
import plotly.express as px
import plotly.io as pio
pio.renderers.default = "notebook"

python
modin_df = pd.DataFrame(dict(a=[1,3,2,4], b=[3,2,1,0]))
pandas_df = pandas.DataFrame(dict(a=[1,3,2,4], b=[3,2,1,0]))
python
# Create a visualization with Modin df
fig2 = px.bar(modin_df)
fig2.show()
# py.iplot(fig2 , filename='jupyter-basic_bar')
python
# Create a visualization with pandas df
fig2 = px.bar(pandas_df)
fig2.show()
python
# Create a visualization with Modin df
fig = px.line(modin_df)
fig.show()
python
# Create a visualization with pandas df
fig = px.line(pandas_df)
fig.show()
python
# Create a visualization with Modin df
fig = px.area(modin_df)
fig.show()
python
# Create a visualization with pandas df
fig = px.area(pandas_df)
fig.show()
python
# Create a visualization with Modin df
fig = px.area(modin_df)
fig.show()
python
# Create a visualization with pandas df
fig = px.area(pandas_df)
fig.show()
python
# Create a visualization with Modin df
fig = px.violin(modin_df)
fig.show()
python
# Create a visualization with pandas df
fig = px.violin(pandas_df)
fig.show()
python
# Create a visualization with Modin df
fig = px.box(modin_df)
fig.show()
python
# Create a visualization with pandas df
fig = px.box(pandas_df)
fig.show()
python
# Create a visualization with Modin df
fig = px.histogram(modin_df, opacity=0.5, orientation='h', nbins=5)
fig.show()
python
# Create a visualization with pandas df
fig = px.histogram(pandas_df, opacity=0.5, orientation='h', nbins=5)
fig.show()
python
# Create a visualization with Modin df
# Example from https://plotly.com/python/mapbox-county-choropleth/#choropleth-map-using-plotlyexpress-and-carto-base-map-no-token-needed
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)
import modin.pandas as pd
modin_df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})
fig = px.choropleth(modin_df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           scope="usa",
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

python
# Create a visualization with pandas df
# Example from https://plotly.com/python/mapbox-county-choropleth/#choropleth-map-using-plotlyexpress-and-carto-base-map-no-token-needed
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)
import pandas
pandas_df = pandas.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

fig = px.choropleth(pandas_df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           scope="usa",
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()