Skip to content

Interactive

interactive

Wrapper for a plotnine ggplot object to make it interactive.

It automatically extracts tooltips and grouping information from the plot mapping if present.

Parameters:

Name Type Description Default
gg ggplot

The original plotnine ggplot object.

required
kwargs dict

Additional arguments passed to plt.savefig().

{}
from plotnine import ggplot, aes, geom_point
from ninejs import interactive, css, save

p = ggplot(df, aes("x", "y", tooltip="label")) + geom_point()
(
    interactive(p)
    + css(from_file="style.css")
    + save("chart.html")
)

Save to HTML file

Utility class to save an interactive plot to an output HTML file.

interactive(p) + save("output.html")

Export to HTML string

Utility class to export an interactive plot as an HTML string.

html_plot: str = interactive(p) + to_html()

Export to iframe HTML string

Utility class to export an interactive plot as an iframe HTML string.

iframe_plot: str = interactive(p) + to_iframe(height=650)