Package: segretini-matplottini
segretini-matplottiniA 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, acorrelation_scatterplot, a stackedrooflineplot, atimeseriesplot withstems, and aridgeplot. Find other examples below!🚂 InstallationWhat do you want do to withsegretini-matplottini? Pick the installation that suits you best.I want to usesegretini-matplottinias a package in my projectsInstallsegretini-matplottiniwithpip.pipinstallsegretini-matplottiniI want to run the examplesClone the repository and installsegretini-matplottiniwithpip. You might want to do so in a dedicatedcondaenvironment.gitclonehttps://github.com/AlbertoParravicini/segretini-matplottini.gitcdsegretini-matplottini
condacreate-nsegretini_matplottinipython=3.9
condaactivatesegretini_matplottini
pipinstall-e.I want to run the examples and the notebooksIf you want to play with notebooks, also installjupyter.pipinstall".[notebook]"I likesegretini-matplottiniso much that I want to contribute to itJump ahead to theDevelopment notessection!✍️ Repository StructureThese are the most important folders ofsegretini-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
    ├── notebooks    -> Jupyter notebooks and tutorials
    ├── 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 startedThe best way to get started is to check out theplotsfolder, to find plots generated withsegretini-matplottini.
If you find a plot you like, you can find the code to generate it in theexamplesfolder.📚 NotebooksIf you do not know where to start from, and you do not have a lot of experience with Matplotlib and Seaborn, check out thenotebooksfolder.1_getting_started_with_barplots.ipynbprovides an introduction to Matplotlib and Seaborn, and guides the reader into creating a beautiful barplot. You will learn principles that lie behind any great visualization, and the basic concepts of Matplotlib and Seaborn.🖼️ Some plots available insegretini-matplottiniThis is a non-inclusive list of custom plots that are available out-of-the-box insegretini-matplottini.correlation_scatterplotvisualizes the relation between two variables, combining a scatterplot, a 2D density plot, and a linear regression with confidence intervals. Learn more withthisexample.ridgeplotshows 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 withthisexample.rooflineplots theRoofline modelfor the input operational intensity and performance values. Learn more withthisexample.binary_classficationsummarizes the performance of a binary classifier, plotting curves such as ROC, Precision-Recall, and F1 score for different classification thresholds. Learn more withthisexample.🧪 Some utilities available insegretini-matplottiniThe astute reader might say "Hey, I don't need any of those plots, why should I care aboutsegretini-matplottini?".
There's a lot more than plotting functions! Theutilscan be applied to any Matplotlib plot, to simplify your life when it comes to creating complex visualizations.datacontains functions to preprocess your experiment results byremoving outliersand computing therelative performancefrom absolute performance numbers.colorsprovides utilities to convert your palettes tograyscaleto check how your plot will look when printed in black-and-white or when seen by a color deficient person, and to simplify thecreation of palettesgiven the start and end colors. It also has plenty of beautiful colors to choose from, validated for black and white printing and color blindness.plotis the source for general plotting utilities, fromcomputingandaddinglabels to barplots tosaving plotswith a standardized structure, so they won't get lost or overwritten by accident.In the examples below, abinary_classificationplot with a few of the available sub-plots turned on, and abarplotthat takes advantage of theutilsto compute relative performance and add labels to bars.👨‍🔬 Development notesIf you want to hacksegretini-matplottiniitself, you will most likely want to clone it with SSH, and install it inside acondaenvironment, ineditablemode withdevdependencies. Also, install thepre-commithooks to obtain linting and quality checks when creating a commit.gitclonegit@github.com:AlbertoParravicini/segretini-matplottini.gitcdsegretini-matplottini
condacreate-nsegretini_matplottinipython=3.9
condaactivatesegretini_matplottini
pipinstall-e".[dev,notebook]"pre-commitinstallWe useblack,mypy, andrufffor 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.--configpyproject.tomlmypy.--configmypy.ini
ruff.--fix--configruff.tomlBuilding and releasingNew releases ofsegretini-matplottiniare built and uploaded topypievery time a pull request is merged tomaster. Remember to update theversionfield inpyproject.toml, or the release onpypiwill fail.💡 Tips and TricksAn ever-growing collection of tips I've found or discovered along the way, together with some nice resources I like a lot.📚 ResourcesSubtleties 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.🎨 ColorsPicking 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 usesegretini_matplottini.utils.convert_color_to_grayscaleor do a print preview after saving your plot as PDF.
If colors are too similar, try adjusting theL(lightness) in theHSLrepresentation, or theB(brightness) in theHSBrepresentation.
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 usesegretini_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.