LetsPlot#
- class 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, **kwargs) None#
Configure Lets-Plot HTML output. This method should typically be called before rendering any plots. Depending on the usage, Lets-Plot generates different HTML to show plots. In most cases Lets-Plot will detect the type of the environment automatically. Use this method to adjust or override the autoconfigured output mode.
- Parameters:
- isolated_framebool
True - generate HTML which can be used in iframe or in a standalone HTML document. False - preload Lets-Plot JS library. Notebook cell output will only consist of HTML for the plot rendering. Default: 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 a notebook without the Internet connection. False - load Lets-Plot JS library from CDN. Default: ‘connected’ mode in the production environment, ‘offline’ mode in the 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 don’t work!
- show_statusbool, default=False
Whether to show the Lets-Plot JS library loading status. Only applicable when the Lets-Plot JS library is preloaded.
- **kwargs
Advanced display options for developers testing in new environments or debugging rendering behavior. These options control the underlying HTML rendering:
- isolated_webview_panelbool
If True, generates HTML for an isolated webview panel with dynamic script loading. When enabled, the ‘isolated_frame’ parameter is ignored.
- width_modestr
Plot width sizing mode: ‘fixed’, ‘min’, ‘fit’, or ‘scaled’. Requires height_mode to also be specified.
- height_modestr
Plot height sizing mode: ‘fixed’, ‘min’, ‘fit’, or ‘scaled’. Requires width_mode to also be specified.
- widthfloat
Explicit width value in px (used with certain sizing modes).
- heightfloat
Explicit height value in px (used with certain sizing modes).
- force_immediate_renderbool
Controls the timing of plot rendering. If True, renders plot immediately. If False, waits for the ResizeObserver event to ensure proper DOM layout.
- responsivebool
If True, the plot automatically resizes when the container is resized.
- height100pctbool
If True, sets the plot container div height to 100%.
Sizing modes:
‘fixed’: Uses specified width/height or default size (not responsive)
‘min’: Uses smallest of: default size, specified size, and container size
‘fit’: Uses container size or specified size if provided
‘scaled’: Adjusts to preserve the aspect ratio
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.8.2: static SVG output configured.
- classmethod set(settings: Dict)#
Set up library options. For more info see 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 theexecparameter.- 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
newparameter is only applicable when theexecparameter is not specified. Please note that thenewparameter 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()