Skip to main content

Format Matplotlib Plots for thesis, scientific papers and reports.

Project description

LovelyPlots

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

pip install LovelyPlots

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 matplotlib.pyplot as plt
plt.style.use('ipynb')

Styles can be combined:

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 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 ['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:

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.

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 matplotlib.pyplot as plt
import LovelyPlots.utils as pp

plt.style.use('ipynb')
pp.set_font('my_font.tiff')

Tips and Tricks

Adobe illustrator

Unfornunatly, mathtext (and thus nicely formated scientific notation) will mess up Adobe illustrator ability to detect text objects, and is thus not activate 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 on 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 restina display support by adding the following lines to the begining on your python script:

import LovelyPlots.utils as pp
pp.use_retina()

Aknoledgements

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

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

LovelyPlots-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distributions

LovelyPlots-0.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

LovelyPlots-0.0.1-py2.py3-none-any.whl (4.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file LovelyPlots-0.0.1.tar.gz.

File metadata

  • Download URL: LovelyPlots-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for LovelyPlots-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fdce2bdb5d0de3d6f3f08500f21e0af5607935b6a8eda24beae05ac8d433aacf
MD5 b6b7daa3828997bff0bc79d3dcd1bee3
BLAKE2b-256 131f9f680e939bcd76fd2708da5d43d49889f95cbe4131f3b493e539d5aa68b4

See more details on using hashes here.

File details

Details for the file LovelyPlots-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: LovelyPlots-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for LovelyPlots-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3716d87507101b54ca3fcad04160e364cf64a4f0d332d7fde8da09674ea9a49
MD5 703d75a5b98182e9d3303610c99e2e4d
BLAKE2b-256 5cdb6c12eaacccab3a972f713e79f650a20308c12fc3223669a0aba20a0b3746

See more details on using hashes here.

File details

Details for the file LovelyPlots-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for LovelyPlots-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0f2f3f63fd1f099aca140065360b29f71b7475d8cc646575dd2ee38e9383d2a1
MD5 1de55a4e8fc4c6ce3dbe2a36552854cb
BLAKE2b-256 73c66e2f615bebfb30692ec77b2cc8ab0696cebc72714fb5e3c4291a3ed066aa

See more details on using hashes here.

Supported by

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