Lets-Plot Documentation
repository·master·Indexed 23 days ago
https://github.com/jetbrains/lets-plotA multiplatform plotting library built on the Grammar of Graphics for Python and Kotlin developers. It provides tools for creating composable statistical graphics, including a flexible number formatting system with SI prefix support, and integration options for Kotlin Notebooks, Compose Multiplatform, JVM, and Kotlin/JS. The library also includes a JavaScript package for browser-based rendering and a SciView plugin for interactive plotting in JetBrains IDEs.
What's inside Lets-Plot
- Lets-Plot is a multiplatform plotting library based on the Grammar of Graphics. It allows users to create complex statistical graphics by composing independent components. It is available for both Python and Kotlin ecosystems.
Serve a development JS package for Jupyter testing
masterWhen using a "dev" version of the Python package,
lets-plotembeds the current development JS into Jupyter notebooks. To serve the development JS script from thejs-packageproject:- Build the development JS package:
./gradlew js-package:jsBrowserDevelopmentWebpack- Start a local web server to serve the files (e.g., on port 8080):
python -m http.server 8080The JS library can be found in the
js-package/build/kotlin-webpack/js/developmentExecutablefolder.Obtain plot specification JSON from Jupyter
masterTo debug plots by extracting their JSON specification from a Jupyter notebook, follow these steps:
- Install
pickleshare: Run!pip install picklesharein a Jupyter cell and restart the kernel. - Install the hook: Run the installation script to add the
_repr_html_hook to your IPython startup directory (typically~/.ipython/profile_default/startup/):./install_lets_plot_hook.sh - Generate Plot: Run any cell that produces a plot.
- Copy Spec: Click the "Copy Spec" button located in the top-right corner of the plot to copy the JSON string to your clipboard.
- Use in Debugger: Use the copied JSON string by setting the
PLOT_SPECenvironment variable in thePlotSpecDebuggerRun Configuration, or paste it directly into the app's editor element.
./install_lets_plot_hook.sh- Install
Build manylinux_x64 image for release
masterTo build the custom
manylinux_x64Docker image (which includes ImageMagick), navigate to themanylinux-x64-imagedirectory and run the provided build script.cd manylinux-x64-image ./build_image.shInstall the Lets-Plot Python package locally
masterTo install your locally built version of
lets-plot:- Change directory to
lets-plot/python-package. - Create or activate your desired Python environment.
- Run the following command to reinstall the package from the local
dist/directory without dependencies:
pip install --no-index --find-links=dist/ lets-plot --no-deps --force-reinstall- Change directory to
Prerequisites for building manylinux Docker images
masterTo build custom
manylinuximages (which include ImageMagick) for Lets-Plot, your Linux build host must meet these requirements:- Docker: Must be installed on the host.
- QEMU: Required for cross-architecture builds (specifically for
aarch64onx86_64hosts). On Ubuntu, install via:sudo apt update && sudo apt install qemu binfmt-support qemu-user-static - QEMU Registration: Register the QEMU script using the
multiarch/qemu-user-staticDocker image:docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - QEMU Binary: Copy the
qemu-aarch64-staticbinary to themanylinux-arm-imagedirectory:cp /usr/bin/qemu-aarch64-static ./manylinux-arm-image/.
sudo apt update sudo apt install qemu binfmt-support qemu-user-static docker run --rm --privileged multiarch/qemu-user-static --reset -p yes cp /usr/bin/qemu-aarch64-static ./manylinux-arm-image/.Run the browser demo
masterTo run the browser-based demos, you must first build the JavaScript package module, then build the browser demo module, and finally execute a demo using the
demoRunnerMainentry point.- Build the
js-packagemodule:./gradlew :js-package:build - Build the
demo-plot-browsermodule:./gradlew :demo-plot-browser:build - Run any demo inside the
demoRunnerMain.
./gradlew :js-package:build ./gradlew :demo-plot-browser:build- Build the
Use Lets-Plot with Python
masterLets-Plot provides a bridge between R (ggplot2) and Python for data visualization. For detailed usage, API references, and tutorials, visit the official Python documentation site.
https://lets-plot.org/pythonSetup the Python module using Conda
masterTo work with the Python sources in IntelliJ IDEA (IDEA), you must create a Python module manually as this is not a Gradle-based module.
- Create the Conda environment: Use the provided environment file to create an environment named
lets-plot-python-module. - Configure IDEA:
- Ensure the IDEA
Pythonplugin is installed. - Create a new Python module with the content root set to
<path>/lets-plot/python-package. - Set the
lets-plot-python-moduleconda environment as the "Module SDK" for this module.
- Ensure the IDEA
- Configure Test Runner: To run Python tests within IDEA, set
pytestas the test runner in Preferences | Tools | Python Integrated Tools.
conda env create -f lets-plot/python-package/module_env.yml- Create the Conda environment: Use the provided environment file to create an environment named
Run tests against the lets-plot package
masterTo run tests against the
lets-plotpackage installed in your module environment, follow these steps:- Navigate to the package directory:
lets-plot/python-package. - Update the
lets-plot-python-moduleconda environment using themodule_env.ymlfile. - Install the development version of Lets-Plot into the
lets-plot-python-moduleenvironment using the local distribution files.
- Navigate to the package directory:
Build the Lets-Plot Python package
masterDepending on your changes, you can perform a full build or a targeted Python-only build.
Full Build with Gradle
Use this method to build both the Kotlin multiplatform binaries and the Python package. The target Python version is determined by your
local.propertiesconfiguration../gradlew :python-package-build:buildPython Package Only Build
If you have only modified Python code, you can rebuild just the Python wheel. Prerequisites:
- You must be inside the
python-packagedirectory. - You must have an active Python environment with the
buildpackage installed. - The resulting wheel will target the Python version of your active environment.
python -m build -w- You must be inside the
Use Lets-Plot with Kotlin
masterLets-Plot supports several Kotlin environments:
- Notebooks: Create plots in Kotlin Notebook, Datalore, Jupyter with Kotlin Kernel, or any notebook supporting a
Kotlin Kernel. - Compose Multiplatform: Embed charts in Compose Multiplatform applications via the
Lets-Plot Compose Frontendproject. - JVM and Kotlin/JS: Embed charts in JVM (Swing, JavaFX) and Kotlin/JS applications.
For the core API, refer to the Lets-Plot Kotlin API project. Documentation is available at lets-plot.org/kotlin.
- Notebooks: Create plots in Kotlin Notebook, Datalore, Jupyter with Kotlin Kernel, or any notebook supporting a