Lets-Plot

4.9.0 · active · verified Thu Apr 16

Lets-Plot is an open-source, multiplatform plotting library for statistical data based on the Grammar of Graphics, heavily influenced by R's ggplot2. It provides a Python API for creating both static and interactive charts in notebooks and IDEs, supporting various data formats like Pandas DataFrames and NumPy. The current version is 4.9.0, with a regular release cadence often tied to its Kotlin counterpart.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic scatter plot with a smoothed regression line, colored by category, using Pandas DataFrame as input. It includes the essential `LetsPlot.setup_html()` call for notebook environments.

import numpy as np
import pandas as pd
from lets_plot import *

LetsPlot.setup_html()

data = pd.DataFrame({
    'x': np.random.normal(0, 1, 100),
    'y': np.random.normal(1, 1.5, 100),
    'category': np.random.choice(['A', 'B'], 100)
})

plot = (ggplot(data, aes(x='x', y='y', color='category')) +
        geom_point(size=5, alpha=0.6) +
        geom_smooth(method='lm', color='black', linetype='dashed') +
        ggtitle('Scatter Plot with Regression Line')
       )

plot

view raw JSON →