An open source library for statistical plotting
Project description
Lets-Plot for Python
Latest Release | |
License | |
OS | Linux, MacOS, Windows |
Python versions | 3.6, 3.7, 3.8 |
Implementation Overview
The Lets-Plot python extension includes native backend and a Python API, which was mostly based on the ggplot2
package well-known to data scientists who use R.
R ggplot2
has extensive documentation and a multitude of examples and therefore is an excellent resource for those who want to learn the grammar of graphics.
Note that the Python API being very similar yet is different in detail from R. Although we have not implemented the entire ggplot2 API in our Python package, we have added a few new features to our Python API.
You can try the Lets-Plot library in Datalore. Lets-Plot is available in Datalore out-of-the-box and is almost identical to the one we ship as PyPI package. This is because Lets-Plot is an offshoot of the Datalore project from which it was extracted to a separate plotting library.
One important difference is that the python package in Datalore is named datalore.plot and the package you install from PyPI has name lets_plot.
The advantage of Datalore as a learning tool in comparison to Jupyter is that it is equipped with very friendly Python editor which comes with auto-completion, intentions, and other useful coding assistance features.
Installation
1. For Linux and Mac users:
To install the Lets-Plot library, run the following command:
pip install lets-plot
2. For Windows users:
Install Anaconda3 (or Miniconda3), then install MinGW toolchain to Conda:
conda install m2w64-toolchain
Install the Lets-Plot library:
pip install lets-plot
Quick start with Jupyter
To evaluate the plotting capabilities of Lets-Plot, add the following code to a Jupyter notebook:
import numpy as np
from lets_plot import *
LetsPlot.setup_html()
np.random.seed(12)
data = dict(
cond=np.repeat(['A','B'], 200),
rating=np.concatenate((np.random.normal(0, 1, 200), np.random.normal(1, 1.5, 200)))
)
ggplot(data, aes(x='rating', fill='cond')) + ggsize(500, 250) \
+ geom_density(color='dark_green', alpha=.7) + scale_fill_brewer(type='seq') \
+ theme(axis_line_y='blank')
Example Notebooks
Try the following examples to study more features of the Lets-Plot
library.
-
Quickstart in Jupyter: quickstart.ipynb
-
Histogram, density plot, box plot and facets: distributions.ipynb
-
Error-bars, crossbar, linerange, pointrange, points, lines, bars, dodge position: error_bars.ipynb
-
Points, point shapes, linear regression, jitter position: scatter_plot.ipynb
-
Smoothing: linear, LOESS: geom_smooth.ipynb
-
Points, density2d, polygons, density2df, bin2d: density_2d.ipynb
-
Tiles, contours, polygons, contourf: contours.ipynb
-
Raster geom, Image geom: image_fisher_boat.ipynb
-
Various presentation options: legend_and_axis.ipynb
GeoDataFrame support (Shapely and GeoPandas).
GeoPandas GeoDataFrame
is supported by the following geometry layers: geom_polygon
, geom_map
, geom_point
, geom_text
, geom_rect
.
-
Map building basics with Lets-Plot and GeoPandas: geopandas_naturalearth.ipynb
-
An inset map of Kotlin island: geopandas_kotlin_isl.ipynb
Nonstandard plotting functions
The following features of Lets-Plot
are not available or have different implementation in other Grammar of Graphics
libraries.
-
ggsize()
- sets the size of the plot. Used in many examples starting fromquickstart
. -
geom_density2df()
- fills space between equal density lines on a 2D density plot. Similar togeom_density2d
but supports thefill
aesthetic.Example: density_2d.ipynb
-
geom_contourf()
- fills space between the lines of equal level of the bivariate function. Similar togeom_contour
but supports thefill
aesthetic.Example: contours.ipynb
-
geom_image()
- displays an image specified by a ndarray with shape (n,m) or (n,m,3) or (n,m,4).Example: image_101.ipynb
Example: image_fisher_boat.ipynb
-
gg_image_matrix()
- a utility helping to combine several images into one graphical object.Example: image_matrix.ipynb
GGBanch
GGBunch allows to show a collection of plots on one figure. Each plot in the collection can have arbitrary location and size. There is no automatic layout inside the bunch.
Examples:
Data sampling
Sampling is a special technique of data transformation, which helps dealing with large datasets and overplotting.
Learn more about sampling in Lets-Plot.
Artistic demos
A set of interesting notebooks using Lets-Plot
library for visualization.
What is new in 1.3.0
SVG/HTML export to file.
export_svg
function takes plot specification and filename as parameters and saves SVG representation of the plot to
a file in the current working directory.
from lets_plot import *
p = ggplot()...
# export SVG to file
from lets_plot.export.simple import export_svg
export_svg(p, "p.svg")
export_html
function takes plot specification and filename as parameters and saves dynamic HTML to a file in the current
working directory.
When viewing this content the internet connection is required.
export_html
has one more option - iframe
. If iframe=True
then Lets-PLot
will wrap output HTML into iframe
.
from lets_plot import *
p = ggplot()...
# export HTML to file
from lets_plot.export.simple import export_html
export_html(p, "p.htm")
Example notebook: export_SVG_HTML
Offline mode for Jupyter notebooks.
In classic Jupyter notebook the LetsPlot.setup_html()
statement by default pre-loads Lets-Plot
JS library from CDN.
Alternatively, option offline=True
will force Lets-Plot
adding the full Lets-Plot JS bundle to the notebook.
In this case, plots in the notebook will be working without an Internet connection.
from lets_plot import *
LetsPlot.setup_html(offline=True)
Cloud-based notebooks are supported
Example notebooks:
Change Log
See Lets-Plot at Github.
License
Code and documentation released under the MIT license. Copyright 2019, JetBrains s.r.o.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file lets_plot-1.3.3rc1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8293150b8bf31b73957eef8124970882b901eff840bb25ef7ed16383478bfcb5 |
|
MD5 | ffc59213d1724077b611100a3a3e1411 |
|
BLAKE2b-256 | db0b4e35eb6f584f4c1d9a4ad14913e58778088feff57fe747697aae2c21ff52 |
File details
Details for the file lets_plot-1.3.3rc1-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a742c504a715c0072ff0fcf80134b76496a96ceec5233c804f3f3a341216abf |
|
MD5 | 1c35f4e3ef995bcd50387d7751057295 |
|
BLAKE2b-256 | 6ba8bd4fa0909021dd8f0bac584c65388e7b53c18e944eb2ecab6dca683b858d |
File details
Details for the file lets_plot-1.3.3rc1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b71d33298566c5b73912470c31a1f36c7686187a2b5b5218af9af6c53812802b |
|
MD5 | 14f5fa46ab2eebb9fdf2f52cbc2d2e88 |
|
BLAKE2b-256 | 1b5beb70e6fee4563122707d3582a587d7aaa8c04d2f06a0443898bd229df57f |
File details
Details for the file lets_plot-1.3.3rc1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 972e7029fd6b52ea2a1cb2b4daa406afad96920cf6ec4a787eff4750a375e480 |
|
MD5 | 3ba89fe0d9361e92487f04961b40b834 |
|
BLAKE2b-256 | 6faa06c0e09f2b7f8b09ccb367da4b52124a850c88ed8bf40d1cc8103bf6e562 |
File details
Details for the file lets_plot-1.3.3rc1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3cc3b759e0a13a35ee296c1c2bc4f2156cd1e1b56f406e6defe9ad6be9740ec |
|
MD5 | 992f72700439182ce85eacd7f9bb7b46 |
|
BLAKE2b-256 | 4268f09891806c5d1c5d58fdb9c5628b48a54c6267f04590ece2c8685e7328be |
File details
Details for the file lets_plot-1.3.3rc1-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a68772d1e44e0231a8407c82c879acf432cc4811c770bd742fa4cfba74a479b6 |
|
MD5 | b8b945b15985d66bd8822cb563226e29 |
|
BLAKE2b-256 | 1727500ec52634c64c2f3207ed02a874b5974467bb7b810b6b66e5f5490d186d |
File details
Details for the file lets_plot-1.3.3rc1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f3112d428f9b67845a2c19f314b2155835e6dd4e5a76aea0bed955fc1a9333 |
|
MD5 | c7f6c1b6b2abf3120053530c6c9a1848 |
|
BLAKE2b-256 | b9c7887dc871147f64a2a9d27fe980d7eb32e960deaf18441050fd93fe96d7de |
File details
Details for the file lets_plot-1.3.3rc1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcef455d7b187bce7dbcc69a25badd90b369034d9fc2b88e19929ff4cb898aa1 |
|
MD5 | e547054f01813207563fb76674536e4a |
|
BLAKE2b-256 | b154a0884fe473d2731f2f10d279f4a8a9f01ec9e14eb3500b3d0d2958c07100 |
File details
Details for the file lets_plot-1.3.3rc1-cp36-cp36m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.3.3rc1-cp36-cp36m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.6m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98afb36b1b3402c8c39e84e47fe65d4853eeee9c579137f07275d264010dfb0d |
|
MD5 | 290c17a87124cda1f0764d38ed990dd6 |
|
BLAKE2b-256 | 88719863de522638fc18a75efde366eb80aa8d965831eefc76624666b2a851e1 |