detroit is wrapper for Python of d3js and Observable Plot.
Project description
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
andPlot
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.2.2.tar.gz
(211.4 kB
view details)
Built Distribution
detroit-1.2.2-py3-none-any.whl
(318.5 kB
view details)
File details
Details for the file detroit-1.2.2.tar.gz
.
File metadata
- Download URL: detroit-1.2.2.tar.gz
- Upload date:
- Size: 211.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3281e234637e5e40d2879719ae61bf0b25dee8c3c93546e6e193d99e4d5e4633 |
|
MD5 | 38e8a1a504b41d09947011270bc06993 |
|
BLAKE2b-256 | e0c65ac5de8cfe0938a1c71bcd6355d5540833194a59b6a6e886150301a41b16 |
File details
Details for the file detroit-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: detroit-1.2.2-py3-none-any.whl
- Upload date:
- Size: 318.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe50614d3e40f18f8c8dba5bffe43f7b44d61114bd45366ddc595ec8c1104170 |
|
MD5 | b7a8e848d9873ff8d421803e1bdfd8a9 |
|
BLAKE2b-256 | 0a3e1f2cdaca2ae631e8e3c96cfc0904f3a1d66a12d81e9524e9855467613b04 |