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.4.0rc2-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e62491b6b90a65a6c550c8463f96b090eb2994831ccf7c3d2150348a070f8a2 |
|
MD5 | 460af8e3b888949a4d0bad02e7a6cfb5 |
|
BLAKE2b-256 | bd787abb36266c459f54593bbf7f781c51f1ae66bc0490b6f5ecc7b667492382 |
File details
Details for the file lets_plot-1.4.0rc2-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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 | 11627d296f07d95d011e51127bb24c5a1209f522293d0640e408ae29c3664c24 |
|
MD5 | 184fa186cdfbbc27c93ecb808ae4cc73 |
|
BLAKE2b-256 | 9d0c8e080a63012e5fe542e82333ba2ad7aa182e17f9054d78781d574007ce1b |
File details
Details for the file lets_plot-1.4.0rc2-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.4 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.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e81efabbd4614d66184f14c62650f1a1a9684178806c364cc3b1f3569116832 |
|
MD5 | 3a53ef93ea6621e51755f77c89f79eaa |
|
BLAKE2b-256 | 1a3942ecf593fa9a7e5ada00db3b75f4a598c01b25bd34a567688d9106a73600 |
File details
Details for the file lets_plot-1.4.0rc2-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a9188a03aa54d24ac436c970465cb63db34f1beecd39c522551e361215c140c |
|
MD5 | d333603c895721281f2c46d8ea444f7b |
|
BLAKE2b-256 | 354d8ead279f57b8ff61ece93ee5d853631520650b7e2f7a15fa9ad32bdfda1c |
File details
Details for the file lets_plot-1.4.0rc2-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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 | 365140ca9349cc4e3adaa2cc2efd8074888cc8d69e52df3e1e6100a315e59d88 |
|
MD5 | 5c10ca369f7350fd80dc17cd998e09e5 |
|
BLAKE2b-256 | 9ce7e97d5dc8a5dc286377d660efe13b91b6cbbefd7a554b2424fcbb7d857105 |
File details
Details for the file lets_plot-1.4.0rc2-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 4.4 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.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eb52d0c464013ef1242ea3c59fcd375eed38d5057378c407cb5fffbae6e9dbc |
|
MD5 | 3d4b9f143a9de807156ddb9edf7ad2e2 |
|
BLAKE2b-256 | 72d6a28f49c585c6cec3a439adb69b75753d129c6762cd2e652aed58615f5941 |
File details
Details for the file lets_plot-1.4.0rc2-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0af9a99c711378042e63e7ba2001ce4a34711c3b54030059f3166479286d2152 |
|
MD5 | 6dfc2e98a701e4c3dd3206dc23ff703b |
|
BLAKE2b-256 | 41310bc47d616c25c92b0a2cbfae3d8ecc6d6c06077fbfced5599c7e6e0954f9 |
File details
Details for the file lets_plot-1.4.0rc2-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-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 | a89bf2e37663dfedd69ac093262bdf9bd6dde4299ab6722c75cffe08924f3182 |
|
MD5 | e2617f97ce047109f2d6324635798293 |
|
BLAKE2b-256 | 14df4838520017a3c501b2e149ba10aa0a8b8cbfa82c5d8a18dfd3bd6be83515 |
File details
Details for the file lets_plot-1.4.0rc2-cp36-cp36m-macosx_10_7_x86_64.whl
.
File metadata
- Download URL: lets_plot-1.4.0rc2-cp36-cp36m-macosx_10_7_x86_64.whl
- Upload date:
- Size: 4.5 MB
- Tags: CPython 3.6m, macOS 10.7+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2.post20191201 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6acc515a7e6aaaf28b06080bf4969cb2ee153fd19a63d3c8d024d69ea7fc0137 |
|
MD5 | 6b58a490da918f942915014ae54dac76 |
|
BLAKE2b-256 | 62f09a23c5a90e6dfccb0c9470f69644a18b077cf6f49db625cd902a25ac041b |