How to use Matplotlib and Seaborn
This guide shows you how to use Matplotlib and its relative [Seaborn]((https://seaborn.pydata.org/) to create plots.
By default, Deephaven does not come with Matplotlib or Seaborn, so you can either access the specific Matplotlib Deephaven example or extend the Deephaven Dockerized set up. Both options are documented below.
Quickstart
To get up and running with Matplotlib and Seaborn, clone the Matplotlib Deephaven base repo, enter its directory, and then run docker-compose up -d
as usual:
git clone https://github.com/deephaven-examples/deephaven-matplotlib-base.git
cd deephaven-matplotlib-base
docker-compose up --build -d
This starts the Deephaven IDE with all the needed packages.
Now, you're ready to use these plotting libraries. Open the IDE to try our sample queries.
Extend Deephaven
If instead you wish to extend the Deephaven build, you can follow the Launch Deephaven from pre-built images steps from the Quickstart guide.
To launch the IDE in a Python session, run:
compose_file=https://raw.githubusercontent.com/deephaven/deephaven-core/main/containers/python-examples/base/docker-compose.yml
curl -O "${compose_file}"
Once you have the docker-compose.yml
file pulled down, define your own web Docker image in web/Dockerfile
that includes the plug-ins you would like to use. In this case, we are installing Matplotlib.
Create subdirectory
web
in the same folder as yourdocker-compose.yml
:mkdir web
Create the
Dockerfile
for web and open for editing:vi web/Dockerfile
Paste the following into the
web/Dockerfile
and save:# Pull the web-plugin-packager image
FROM ghcr.io/deephaven/web-plugin-packager:main as build
# Specify the plugins you wish to use. You can specify multiple plugins separated by a space, and optionally include the version number, e.g.
# RUN ./pack-plugins.sh <js-plugin-name>[@version] ...
# For a list of published plugins, see https://www.npmjs.com/search?q=keywords%3Adeephaven-js-plugin
# Here is how you would install the matplotlib and table-example plugins
RUN ./pack-plugins.sh @deephaven/js-plugin-matplotlib @deephaven/js-plugin-table-example
# Copy the packaged plugins over
FROM ghcr.io/deephaven/web:${VERSION:-latest}
COPY --from=build js-plugins/ /usr/share/nginx/html/js-plugins/
Many plug-ins will also require a server side component. To define the plug-ins used on the server, create a server/Dockerfile
similar to above:
Create subdirectory
server
in the same folder as yourdocker-compose.yml
:mkdir server
Create the
Dockerfile
for server and open for editing:vi server/Dockerfile
Paste the following into the
server/Dockerfile
and save:FROM ghcr.io/deephaven/server:${VERSION:-latest}
# pip install any of the plugins required on the server
RUN pip install deephaven-plugin-matplotlib
After building, you need to specify using that build in your docker-compose
. Do this by modifying the existing docker-compose.yml
file and replace the web and server definitions with the following:
services:
server:
# Comment out the image name
# image: ghcr.io/deephaven/server:${VERSION:-latest}
# Build from your local Dockerfile you just created
build: ./server
...
web:
# Comment out the image name
# image: ghcr.io/deephaven/web:${VERSION:-latest}
# Build from your local Dockerfile you just created
build: ./web
When you're done, your directory structure should look like:
.
├── docker-compose.yml
├── server
│ └── Dockerfile
└── web
└── Dockerfile
Everything's ready to go! Now after running docker-compose up
as normal, you can use your custom image with your JS plug-ins installed. See what you can create!
Matplotlib examples
Here is the basic usage of Matplotlib to show one figure:
The full functionaly of Matplotlib is avilable inside the Deephaven IDE:
Here are some 3D examples from Rashida Nasrin Sucky. The data, available from Kaggle, needs to be placed in the data directory. For more information see our guide on Docker data volumes.
Seaborn examples
Here is the basic usage of Seaborn: