Plots and Visualizations
Datapane supports all major Python visualization libraries, allowing you to add interactive plots and visualizations to your report.
The dp.Plot block takes a plot object from one of the supported Python visualisation libraries and renders it in your report.
Datapane will automatically wrap your visualization or plot in a dp.Plot block if you pass it into your report directly.
It takes the following parameters:
    name: Sets the name of the chart within the caption
    caption : Adds a caption beneath your plot
    responsive: Boolean (True by default) which controls whether the plot fills the block. Set to False if you want to manually specify the height and width within the plot object.
1
dp.Plot(fig, name="fig1", caption="Chart showing average life expectancy", responsive=False)
Copied!
Datapane currently supports the following libraries:
If you're using another visualization library e.g. Pyvis for networks, try saving your chart as a local HTML file and wrapping that in a dp.HTML block.

Altair

Altair is a declarative statistical visualization library for Python, based on Vega and Vega-Lite. Altair’s API is simple, friendly and consistent and built on top of the powerful Vega-Lite visualization grammar. This elegant simplicity produces beautiful and effective visualizations with a minimal amount of code.
To get started using Altair to make your visualizations, begin with Altair's Documentation
1
import altair as alt
2
import datapane as dp
3
from vega_datasets import data as vega_data
4
gap = pd.read_json(vega_data.gapminder.url)
5
6
select_year = alt.selection_single(
7
name='select', fields=['year'], init={'year': 1955},
8
bind=alt.binding_range(min=1955, max=2005, step=5)
9
)
10
alt_chart = alt.Chart(gap).mark_point(filled=True).encode(
11
alt.X('fertility', scale=alt.Scale(zero=False)),
12
alt.Y('life_expect', scale=alt.Scale(zero=False)),
13
alt.Size('pop:Q'),
14
alt.Color('cluster:N'),
15
alt.Order('pop:Q', sort='descending'),
16
).add_selection(select_year).transform_filter(select_year)
17
18
dp.Report(dp.Plot(alt_chart)).upload(name='time_interval')
Copied!

Bokeh

Bokeh is an interactive visualization library which provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large datasets.
To get started using Bokeh to make your visualizations, begin with Bokeh's User Guide.
1
from bokeh.plotting import figure, output_file, show
2
from bokeh.sampledata.iris import flowers
3
import datapane as dp
4
5
# Create scatter plot with Bokeh
6
colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}
7
colors = [colormap[x] for x in flowers['species']]
8
9
bokeh_chart = figure(title = "Iris Morphology")
10
bokeh_chart.xaxis.axis_label = 'Petal Length'
11
bokeh_chart.yaxis.axis_label = 'Petal Width'
12
13
bokeh_chart.circle(flowers["petal_length"], flowers["petal_width"],
14
color=colors, fill_alpha=0.2, size=10)
15
16
# Upload the report
17
dp.Report(dp.Plot(bokeh_chart)).upload(name='bokeh_plot')
Copied!

Matplotlib

Matplotlib is the original Python visualisation library, often supported and used with Jupyter Notebooks. Matplotlib plots are not interactive in Datapane Reports, but are saved as SVGs so can be viewed at high fidelity.
Higher-level matplotlib libraries such as Seaborn are also supported, and can be used in a similar way to the matplotlib example below,
1
import matplotlib.pyplot as plt
2
import pandas as pd
3
import datapane as dp
4
from vega_datasets import data as vega_data
5
6
gap = pd.read_json(vega_data.gapminder.url)
7
# gap.plot.scatter()
8
fig = gap.plot.scatter(x='life_expect', y='fertility')
9
dp.Report(dp.Plot(fig)).upload(name="test_mpl")
Copied!
You can pass either a matplotlib Figure or Axes object to dp.Plot, you can obtain the current global figure from matplotlib by running plt.gcf()

Plotly

Plotly's Python graphing library makes interactive, publication-quality graphs.
1
import plotly.express as px
2
import datapane as dp
3
4
df = px.data.gapminder()
5
6
plotly_chart = px.scatter(df.query("year==2007"), x="gdpPercap", y="lifeExp",
7
size="pop", color="continent",
8
hover_name="country", log_x=True, size_max=60)
9
plotly_chart.show()
10
11
dp.Report(dp.Plot(plotly_chart)).upload(name='bubble')
Copied!

Folium

Folium makes it easy to visualize data that’s been manipulated in Python on an interactive leaflet map. It enables both the binding of data to a map for choropleth visualizations as well as passing rich vector/raster/HTML visualizations as markers on the map.
The library has a number of built-in tilesets from OpenStreetMap, Mapbox, and Stamen, and supports custom tilesets with Mapbox or Cloudmade API keys.
If your folium map consumes live data which expires after a certain time, you can automate it to refresh the map on a cadence. See Automation.
1
import folium
2
import datapane as dp
3
4
m = folium.Map(location=[45.5236, -122.6750])
5
6
dp.Report(dp.Plot(m)).upload(name='folium_map')
Copied!
Last modified 1mo ago