Skip to main content

Produce publication-level quality images on top of Matplotlib

Project description

Erwan Pannier - EM2C Laboratory, CentraleSupélec / CNRS UPR 288

Description

Produce publication-level quality images on top of Matplotlib, with a simple call to couple functions at the start and end of your script.

Project GitHub page

For similar librairies, see seaborn, which also add neat high-end API to Matplotlib function calls.

Install

pip install publib

Use

At the beginning of the script, call:

set_style()

After each new axe is plotted, call:

fix_style()

Note that importing publib will already load the basic style.

A few more styles (‘poster’, ‘article’, etc.) can be selected with the function set_style()

Because some matplotlib parameters cannot be changed before the lines are plotted, they are called through the function fix_style() which:

  • changes the minor ticks

  • remove the spines

  • turn the legend draggable by default

Examples

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

A default Matplotlib plot:

mpl.rcdefaults()

x = np.linspace(0,5,250)
y = np.cos(x)**2+np.random.normal(scale=0.5,size=len(x))
yav = np.cos(x)**2
plt.figure()
ax = plt.subplot()
ax.plot(x,y,'o',label='normal distribution')
ax.plot(x,yav,zorder=-1,label='average')
plt.xlabel(r'$x$')
plt.ylabel(r'$\cos^2 x$+noise')
plt.title('matplotlib')
plt.legend(loc='upper left')
plt.ylim((-1.5,3.5))
plt.show()
plt.savefig('mpl_default.png')
mpl\_defaults.png

mpl_defaults.png

And now the same code with the two new lines calling the publib functions

from publib import set_style, fix_style
set_style('article')        # before the first plot

x = np.linspace(0,5,250)
y = np.cos(x)**2+np.random.normal(scale=0.5,size=len(x))
yav = np.cos(x)**2
plt.figure()
ax = plt.subplot()
ax.plot(x,y,'o',label='normal distribution')
ax.plot(x,yav,zorder=-1,label='average')
plt.xlabel(r'$x$')
plt.ylabel(r'$\cos^2 x$+noise')
plt.title('article')
plt.legend(loc='upper left')
plt.ylim((-1.5,3.5))

fix_style('article')  # after the axe has been created

plt.show()
plt.savefig('publib_article.png')
publib\_article.png

publib_article.png

Run the _test() routine in publib.py for more examples.

Changes

  • 0.1.8 : fixed deprecation error messages

  • 0.1.7 : default fonts to Times in article

  • 0.1.6 : improve Readme

  • 0.1.5 : changed those buff_style functions in fix_style

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

publib-0.1.8.zip (22.1 kB view details)

Uploaded Source

File details

Details for the file publib-0.1.8.zip.

File metadata

  • Download URL: publib-0.1.8.zip
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for publib-0.1.8.zip
Algorithm Hash digest
SHA256 3f30f4c1a1aad7a35d8bf99fb84db0aa43e0c8e7e8da53dbb66a57d8154bfdc2
MD5 0dacf132d4983a3122ca24bef923a7f2
BLAKE2b-256 b1caa0596ba5983ce7334ebbdc88e23e68b8f89dc13902cb87ce176de0645b37

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