lets_plot.LetsPlot#

class lets_plot.LetsPlot#

Initialize the library and its options.

classmethod setup_html(*, isolated_frame: bool | None = None, offline: bool | None = None, no_js: bool | None = None, show_status: bool = False) None#

Configure Lets-Plot HTML output. Depending on the usage, LetsPlot generates different HTML to show plots. In most cases LetsPlot will detect type of the environment automatically. Auto-detection can be overwritten using this method parameters.

Parameters:
isolated_framebool

True - generate HTLM which can be used in iframe or in a standalone HTML document. False - pre-load Lets-Plot JS library. Notebook cell output will only consist of HTML for the plot rendering. Default: None - auto-detect.

offlinebool

True - full Lets-Plot JS bundle will be added to the notebook. Use this option if you would like to work with notebook without the Internet connection. False - load Lets-Plot JS library from CDN. Default (None): ‘connected’ mode in production environment and ‘offline’ mode in dev environment.

no_jsbool, default=False

True - do not generate HTML+JS as an output - just static SVG image. Note that without JS interactive maps and tooltips doesn’t work!

show_statusbool, default=False

Whether to show status of loading of the Lets-Plot JS library. Only applicable when the Lets-Plot JS library is preloaded.

Examples

1from lets_plot import *
2LetsPlot.setup_html()
3ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point()

1from lets_plot import *
2LetsPlot.setup_html(isolated_frame=False, offline=True, \
3                    no_js=True, show_status=True)
4ggplot({'x': [0], 'y': [0]}, aes('x', 'y')) + geom_point()
Lets-Plot v4.3.2: static SVG output configured.
-0.4 -0.2 0.0 0.2 0.4 -0.4 -0.2 0.0 0.2 0.4 y x
classmethod set(settings: Dict)#

Set up library options. For more info see https://lets-plot.org/python/pages/basemap_tiles.html#configuring-globally.

Parameters:
settingsdict

Dictionary of settings.

Notes

List of possible settings:

  • html_isolated_frame : preload Lets-Plot JS library or not (bool). Do not use this parameter explicitly. Instead you should call LetsPlot.setup_html().

  • offline : to work with notebook without the Internet connection (bool). Do not use this parameter explicitly. Instead you should call LetsPlot.setup_html().

  • no_js : do not generate HTML+JS as an output (bool). Do not use this parameter explicitly. Instead you should call LetsPlot.setup_html(). Also note that without JS interactive maps and tooltips doesn’t work!

Interactive map settings could also be specified:

  • maptiles_kind : kind of the tiles, could be ‘raster_zxy’ or ‘vector_lets_plot’. Do not use this parameter explicitly. Instead you should construct it with functions maptiles_zxy() and maptiles_lets_plot().

  • maptiles_url : address of the tile server (str). Do not use this parameter explicitly. Instead you should construct it with functions maptiles_zxy() and maptiles_lets_plot().

  • maptiles_theme : tiles theme, could be ‘color’, ‘light’ or ‘dark’. Do not use this parameter explicitly. Instead you should construct it with function maptiles_lets_plot().

  • maptiles_attribution : an attribution or a copyright notice to display on the map as required by the tile license (str, supports HTML links). Do not use this parameter explicitly. Instead you should construct it with function maptiles_zxy().

  • maptiles_min_zoom : minimal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function maptiles_zxy().

  • maptiles_max_zoom : maximal zoom limit (int). Do not use this parameter explicitly. Instead you should construct it with function maptiles_zxy().

Examples

1from lets_plot import *
2from lets_plot import tilesets
3LetsPlot.setup_html()
4LetsPlot.set(tilesets.LETS_PLOT_LIGHT)
5ggplot() + geom_livemap()

1from lets_plot import *
2from lets_plot import tilesets
3LetsPlot.setup_html()
4LetsPlot.set(tilesets.LETS_PLOT_BW)
5ggplot() + geom_livemap()
classmethod set_theme(theme: core.FeatureSpec | core.FeatureSpecArray)#

Set up global theme.

Parameters:
themespec

Theme spec provided by theme(…), theme_xxx(), flavor_xxx() functions, or their sum.

classmethod setup_show_ext(*, exec: str | None = None, new: bool = False) None#

Configure Lets-Plot to show its HTML output in an external browser.

When the “show externally” is set up, an invocation of figire.show() will - generate HTML output - save it to a temporary file - open the file in the default web browser or in a web browser specified by the exec parameter.

Parameters:
execstr, optional

Specify an app to open the generated temporary HTML file. If not specified, the default browser will be used.

newbool, default=False

If True, the URL is opened in a new window of the web browser. If False, the URL is opened in the already opened web browser window. The new parameter is only applicable when the exec parameter is not specified. Please note that the new parameter is not supported by all web browsers and all OS-s.

Examples

1# Show the plot in the default web browser.
2from lets_plot import *
3LetsPlot.setup_show_ext()
4p = ggplot() + geom_point(x=0, y=0)
5p.show()

1# Show the plot in the new window of the default web browser if possible.
2from lets_plot import *
3LetsPlot.setup_show_ext(new=True)
4p = ggplot() + geom_point(x=0, y=0)
5p.show()

1# Show the plot in the Chrome web browser for Windows.
2# This is the default setup path. Replace the file path with your own if it differs.
3from lets_plot import *
4LetsPlot.setup_show_ext(exec = 'C:\Program Files\Google\Chrome\Application\chrome.exe --app=%s')
5p = ggplot() + geom_point(x=0, y=0)
6p.show()

1# Show the plot in the Safari web browser for macOS.
2from lets_plot import *
3LetsPlot.setup_show_ext(exec = 'open -a safari %s')
4p = ggplot() + geom_point(x=0, y=0)
5p.show()

1# Show the plot in the Chrome web browser for macOS in the application mode.
2# This is the default setup path. Replace the path with your own if it differs.
3from lets_plot import *
4LetsPlot.setup_show_ext(exec = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app=%s')
5p = ggplot() + geom_point(x=0, y=0)
6p.show()

1# Show the plot in the Chrome web browser for Linux.
2from lets_plot import *
3LetsPlot.setup_show_ext(exec = 'google-chrome --app=%s')
4p = ggplot() + geom_point(x=0, y=0)
5p.show()