Skip to main content

Colorful recipes and utilities for Matplolib and Seaborn, to create publication-ready plots

Project description

segretini-matplottini

A collection of Matplotlib and Seaborn recipes and utilities collected over years of colorful plot-making, to help researchers create publication-ready plots with ease.

๐Ÿ‘‡ For example, a correlation_scatterplot, a stacked roofline plot, a timeseries plot with stems, and a ridgeplot. Find other examples below!

Grid of example plots

๐Ÿš‚ Installation

What do you want do to with segretini-matplottini? Pick the installation that suits you best.

I want to use segretini-matplottini as a package in my projects

Install segretini-matplottini with pip.

I want to run the examples

Clone the repository and install segretini-matplottini with pip. You might want to do so in a dedicated conda environment.

git clone https://github.com/AlbertoParravicini/segretini-matplottini.git
cd segretini-matplottini
conda create -n segretini_matplottini python=3.9
conda activate segretini_matplottini
pip install .

I want to run the examples and the notebooks

If you want to play with notebooks, also install jupyter.

pip install ".[notebook]"

I like segretini-matplottini so much that I want to contribute to it

Jump ahead to the Development notes section!

โœ๏ธ Repository Structure

These are the most important folders of segretini-matplottini, so you won't get lost when exploring the code.

segretini-matplottini (this folder)
    โ”œโ”€โ”€ segretini_matplottini
    โ”‚   โ”œโ”€โ”€ plot              -> Ready-made plotting functions (e.g. ridgeplots, and Roofline plots)
    โ”‚   โ””โ”€โ”€ utils             -> Other setup files (constants, metadata, etc.)
    โ”‚       โ”œโ”€โ”€ constants.py  -> Default values for shared settings (font size, DPI, etc.)
    โ”‚       โ”œโ”€โ”€ colors.py     -> List of predefined and pretty colors, plus color-related utilities
    โ”‚       โ”œโ”€โ”€ data.py       -> Utilities to preprocess datasets (e.g. outlier removal)
    โ”‚       โ”œโ”€โ”€ legend.py     -> Legend-related utilities (e.g. custom legend styles)
    โ”‚       โ””โ”€โ”€ plot.py       -> General utilities for plotting (e.g. adding labels, saving plots)
    โ”œโ”€โ”€ data         -> Sample data used in example plots
    โ”œโ”€โ”€ examples     -> Recipes to create fancy plots
    โ”œโ”€โ”€ plots        -> Plots generated by examples. If you find something cool, check the code in examples
    โ”œโ”€โ”€ tests        -> Unit tests and end-to-end tests for plotting functions
    โ”œโ”€โ”€ CHANGELOG.md -> List of updates to the codebase. Check here to see what's new
    โ”œโ”€โ”€ README.md   -> This file!
    โ””โ”€โ”€ (...)       -> Configuration files for linters, and other setup files.

๐ŸŒž Getting started

The best way to get started is to check out the plots folder, to find plots generated with segretini-matplottini. If you find a plot you like, you can find the code to generate it in the examples folder.

Some plots available in segretini-matplottini

This is a non-inclusive list of custom plots that are available out-of-the-box in segretini-matplottini.

  • correlation_scatterplot visualizes the relation between two variables, combining a scatterplot, a 2D density plot, and a linear regression with confidence intervals. Learn more with this example.
  • ridgeplot shows the distribution of two variables, grouped by the specified factor. For example, one can visualize the latency of two implementations of the same algorithm, across multiple runs of different datasets. Learn more with this example.
  • roofline plots the Roofline model for the input operational intensity and performance values. Learn more with this example.
  • binary_classfication summarizes the performance of a binary classifier, plotting curves such as ROC, Precision-Recall, and F1 score for different classification thresholds. Learn more with this example.

Some utilities available in segretini-matplottini

The astute reader might say "Hey, I don't need any of those plots, why should I care about segretini-matplottini?". There's a lot more than plotting functions! The utils can be applied to any Matplotlib plot, to simplify your life when it comes to creating complex visualizations.

  • data contains functions to preprocess your experiment results by removing outliers and computing the relative performance from absolute performance numbers.
  • colors provides utilities to convert your palettes to grayscale to check how your plot will look when printed in black-and-white or when seen by a color deficient person, and to simplify the creation of palettes given the start and end colors. It also has plenty of beautiful colors to choose from, validated for black and white printing and color blindness.
  • plot is the source for general plotting utilities, from computing and adding labels to barplots to saving plots with a standardized structure, so they won't get lost or overwritten by accident.

In the examples below, a binary_classification plot with a few of the available sub-plots turned on, and a barplot that takes advantage of the utils to compute relative performance and add labels to bars.

Grid of example plots, binary classification and barplot

๐Ÿ‘จโ€๐Ÿ”ฌ Development notes

If you want to hack segretini-matplottini itself, you will most likely want to clone it with SSH, and install it inside a conda environment, in editable mode with dev dependencies. Also, install the pre-commit hooks to obtain linting and quality checks when creating a commit.

git clone git@github.com:AlbertoParravicini/segretini-matplottini.git
cd segretini-matplottini
conda create -n segretini_matplottini python=3.9
conda activate segretini_matplottini
pip install -e ".[dev,notebook]"
pre-commit install

We use black, mypy, and ruff for formatting, type checking, linting, and sorting imports. Each commit must pass these checks. To run checks manually, run the following commands. Checks also run when creating a commit. You won't be able to commit if a check fails.

black . --config pyproject.toml 
mypy . --config mypy.ini
ruff . --fix --config ruff.toml

Building and releasing

To build a new version of segretini-matplottini, run the following command. Make sure that you have dev dependencies installed.

python -m build

๐Ÿ’ก Tips and Tricks

An ever-growing collection of tips I've found or discovered along the way, together with some nice resources I like a lot.

๐Ÿ“š Resources

  • Subtleties of Color: a six-part guide on how to pick nice colors and create great palettes, from the Earth Observatory NASA blog.
  • Adobe Color: a free web tool to create palettes of different types (shades, complementary, etc.). It also has accessibility tools to test for color blindness safety.

๐ŸŽจ Colors

Picking the right colors is hard! I found the following tips to be very helpful.

  • Not everyone sees colors in the same way: most reviewers will look at your papers after printing them in black & white. Always check for that! You can use segretini_matplottini.utils.convert_color_to_grayscale or do a print preview after saving your plot as PDF. If colors are too similar, try adjusting the L (lightness) in the HSL representation, or the B (brightness) in the HSB representation. Also, a lot of people are color blind, and there are many types of color blindness! It's always better to double-check. To do so, you can use segretini_matplottini.utils.convert_color_to_deficiency.

  • Hidden color biases: people tend to associate implicit meanings with colors. To simplify the matter a lot, green is usually associated with positive things, while red is bad. If your plot is not explicitly comparing classes (for example, you want to show the speed of your algorithm on different datasets), just go for a neutral/positive palette, using colors such as green, blue, and light pink.

  • Add redundant information: if you are plotting many different classes, and use one color per class, it can be difficult to distinguish among them. Instead, add some kind of redundant information. In scatterplots and lineplots you can use different markers (circles, diamonds, etc.), while in barplots you can use different hatches (//// or \\) or add labels to each class.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

segretini-matplottini-0.2.1.tar.gz (6.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

segretini_matplottini-0.2.1-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file segretini-matplottini-0.2.1.tar.gz.

File metadata

  • Download URL: segretini-matplottini-0.2.1.tar.gz
  • Upload date:
  • Size: 6.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for segretini-matplottini-0.2.1.tar.gz
Algorithm Hash digest
SHA256 f66f948cfe4f48e8385393892db493534ad466cee25287a58656cb563ecb7997
MD5 6618076bb30b43861b175a8adfbbb0b9
BLAKE2b-256 c9f004abd7305d6d0c1a8924bc925fc2e16a6a1f2dd2d39173f6e387cf1e8488

See more details on using hashes here.

File details

Details for the file segretini_matplottini-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for segretini_matplottini-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc14f30a47f758ac75bda8a626e551aada11f27ee86d3695e0854a619e02e435
MD5 c2d7fd6456374180b64119ea4f981d95
BLAKE2b-256 dffdf09218cf1fc1186b765529b122074b1e630bcae3b5f554f590c52d13a436

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page