Skip to main content

LovelyPlots

PyPI Version PyPI Downloads doi tests

[!WARNING] As of version 1.0.0, you need to add import lovelyplots before setting the style (plt.style.use('ipynb')).

LovelyPlots is a repository containing matplotlib style sheets to nicely format figures for scientific papers, thesis and presentations while keeping them fully editable in Adobe Illustrator. Additonaly, .svg exports options allows figures to automatically adapt their font to your document's font. For example, .svg figures imported in a .tex file will automatically be generated with the text font used in your .tex file.

Installation

# to install latest PyPI release
pip install LovelyPlots

# to install latest GitHub commit
pip install --upgrade git+https://github.com/killiansheriff/LovelyPlots.git

The pip installation will move all of the matplotlib style files *.mplstyle into the appropriate matplotlib directory.

Usage

LovelyPlots main style is called ipynb. To use it, add the following lines to the begining of your python scripts:

import lovelyplots
import matplotlib.pyplot as plt
plt.style.use('ipynb')

Styles can be combined:

import lovelyplots
import matplotlib.pyplot as plt
plt.style.use(['ipynb','colorsblind34'])

In the above case, the ipynb default color cycle will be overwritten by a 34 colors colorblind safe color cycle called colorsblind34.

If you only wish to apply a style on a specific plot, this can be achieved using:

import lovelyplots
import matplotlib.pyplot as plt

with plt.style.context('ipynb'):
  fig, ax = plt.subplots()
  ax.plot(x, y)

Examples

A few styles are presented here, please see Styles for a list of all implemented styles. The script used to generate these plots can be found here.

:warning: If you use the use_mathtext style, Adobe Illustrator might fail to nicely detect text objects. Please see here for work arounds.

The ['ipynb', 'use_mathtext'] style:

The ['ipynb', 'use_mathtext','colors10-markers'] style:

The ['ipynb', 'use_mathtext','colors5-light'] style:

The ['ipynb', 'use_mathtext', 'colors10-ls'] style:

The ['ipynb'] style:

The ['paper', 'use_mathtext'] style:

Styles

LovelyPlots main style is called ipynb. The latter by default sets the figure size to (4.5, 3.46) inches, uses the default matplotlib font, activate scientific notation and makes sure your matplotlib exports will be editable in Adobe Illustrator. Its default color cycle was set to colors10.

Color cycles

A multitude of color cycles were implemented:

colors5-light

colors5

colors10

colorsblind10

colorsblind34

Can be seen here.

Lines styles, markers and combinations styles

Line styles, markers styles and combinations can be set using the following styles: ls5, marker7, colors10-ls, colors10-markers.

Color maps

Default matplotlib colormaps were implemented and can be used by adding the following styles: cmap-viridis, cmap-inferno, cmap-cividis, cmap-magma, cmap-plasma.

Utils

Specific matplotlibrc parameters can be turned on/off using the following utilities styles: svg_no_fonttype, use_mathtex, use_tex.

Fonts

By default the ipynb style uses the default matplotlib font. However, one can set its favorite font from a TIFF file:

import lovelyplots as lp
import matplotlib.pyplot as plt

plt.style.use('ipynb')
lp.utils.set_font('my_font.tiff')

Tips and Tricks

Adobe Illustrator

Unfortunately, mathtext (and thus nicely formated scientific notation) will mess up Adobe illustrator ability to detect text objects, and is thus not activated by default. If you wish to use it, please add the style use_mathtext.

Latex and SVG files

By default, the ipynb style sets svg.fonttype: none. This allows for plots saved as .svg not to carry font information. Consequently, when opened in another environement, the plot will be generated with the default system font.

For example, this allows .svg plots imported inside a Latex file to directly be generated with the proper document font, without you having to manually edit the fonts to match your document's font. Additonally, you can open the .svg file as text file, find the ugly 1e10 scientific notation and replace it with $10^10$ so that it is nicely formated when included in your .tex file.

An example of how to show an svg in a .tex file:

\usepackage{svg}

\begin{figure}[htbp]
  \centering
  \includesvg{myfig.svg}
\end{figure}

Retina displays

For those using IPython notebooks, you can set retina display support by adding the following lines to the begining on your python script:

import lovelyplots as lp
lp.utils.set_retina()

Useth in Google Colab

To use on Google Colab, you will need to run the following code:

!pip install lovelyplots
import lovelyplots
plt.style.reload_library()
plt.style.use('ipynb')

Acknowledgements

This reprository was inspired by SciencePlots, but adds different styles and crucial functionalities for useth in .tex files and Adobe Illustrator.

Citing

If you use LovelyPlots, please consider citing:

@software{killian_sheriff_2022_6916993,
  author       = {Killian Sheriff},
  title        = {{LovelyPlots, a collection of matplotlib 
                   stylesheets for scientific figures}},
  month        = jul,
  year         = 2022,
  publisher    = {Zenodo},
  version      = {v0.0.26\_LovelyPlots},
  doi          = {10.5281/zenodo.6916993},
  url          = {https://doi.org/10.5281/zenodo.6916993}
}

Release files for lovelyplots 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lovelyplots 1.0.2
File Size Uploaded
lovelyplots-1.0.2.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lovelyplots 1.0.2
File Interpreter ABI Platform
lovelyplots-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 24.4 kB

Release files / lovelyplots-1.0.2.tar.gz

Download URL lovelyplots-1.0.2.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6b6e6cb50975e6681755b55447402e6cca6c21451adf6d1255884fd457739d68
BLAKE2b-256 checksum
How to use checksums
d806948176dd3e96996c40bcc589cd30fa3ebd0a351659af54e3a3ffaf5d0305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / lovelyplots-1.0.2-py3-none-any.whl

Download URL lovelyplots-1.0.2-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d778300203e546d7ff642b2ee16c91fa47f0980574b409148e1cb8976fe6832
BLAKE2b-256 checksum
How to use checksums
17c8dd7dd77f5022b0ae6d377d28dd49b470d820dc2fc51592c2c4860aa6cb2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.0

2 release files

0.0.27

2 release files

0.0.26

1 release file

0.0.24

1 release file

0.0.22

1 release file

0.0.21

1 release file

0.0.20

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page