Plotting

In this section you can find description of tested libraries that are supported with merkury utility functions. These are helper functions to format plot objects as HTML output.

In case you need to use something else: any library that can produce plot in HTML format will work fine with merkury.

  1. Output compatibility
  2. Altair
  3. Bokeh
  4. Matplotlib
  5. Plotly

Output compatibility

Which plotting libraries you can use depening on desired report format.

  HTML Markdown
Altair yes no
Bokeh yes no
Matplotlib yes yes
Plotly yes yes

Altair

Altair example

import altair as alt
from merkury.utils import output_altair

data = alt.Data(values=[{"x": 5, "y": 6}, {"x": 6, "y": 7}, {"x": 7, "y": 4}])
chart = alt.Chart(data).mark_point().encode(
    x="x:Q",
    y="y:Q",
)

print(output_altair(chart))
#HTML

Notes:

  • requires altair_saver
  • does not work in markdown report format (plots require javascript)

Bokeh

Bokeh example

from bokeh.plotting import figure
from merkury.utils import output_bokeh

plot = figure()
plot.circle([1, 2, 3, ], [3, 5, 4, ])

print(output_bokeh(plot))
#HTML

Notes:

  • does not work in markdown report format (plots require javascript)

Matplotlib

Matplotlib example

import matplotlib.pyplot as plt
from merkury.utils import output_matplotlib

fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4], [1, 4, 9, 16])

print(output_matplotlib(fig))
#HTML

Plotly

Plotly example

import plotly.graph_objs as go
from merkury.utils import output_plotly

data = [go.Scatter(
    x = [4, 5, 6, ],
    y = [78, 70, 74, ],
)]

fig = go.Figure(data=data)

print(output_plotly(fig))
#HTML

Notes:

  • requires kaleido