Skip to main content

detroit is wrapper for Python of d3js and Observable Plot.

Project description


PyPI Latest Release Documentation Status BSD-3-Clause

detroit is wrapper for Python of d3js and Observable Plot.

Installation

pip install detroit

Then you will need to install a browser through the Python package playwright. For the moment, only chromium is supported.

playwright install chromium

Features

  • Write as close as possible d3 and Plot code
  • Render one or multiple plots in your browser or in your jupyter notebook
  • Customize style as you want
  • Save them into .svg, .png or .pdf

Quick Example

import polars as pl
from sklearn.datasets import load_digits
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

from detroit import Plot, js, render, save

mnsit = load_digits()
scaler = StandardScaler()
X_scaled = scaler.fit_transform(mnsit.data)
pca = PCA(n_components=2)
components = pca.fit_transform(X_scaled)

# Prepare your data with Polars, Pandas or manually
df = pl.DataFrame(components, schema=["Component 1", "Component 2"])
df = df.insert_column(2, pl.Series("digit", mnsit.target))

plot = Plot.plot({
  "style": {"backgroundColor": "#161b22", "color": "#e6edf3"},
  "symbol": {"legend": js("true")},
  "color": {"scheme": "rainbow"},
  "marks": [
      Plot.dot(js("data"), {
          "x": "Component 1",
          "y": "Component 2",
          "stroke": "digit",
          "symbol": "digit"
      })
  ]
})

render(df, plot, style={"body": {"background": "#161b22", "color": "#e6edf3"}})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detroit-1.1.0.tar.gz (21.2 kB view hashes)

Uploaded Source

Built Distribution

detroit-1.1.0-py3-none-any.whl (23.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page