MCPcopy Index your code
hub / github.com/erwanp/publib

github.com/erwanp/publib @0.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.2.1 ↗ · + Follow
11 symbols 45 edges 6 files 6 documented · 55%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PyPI version Tests Code coverage

Publib

Description

Produce publication-level quality images on top of Matplotlib, with a simple call to a 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, and the Matplotlib default style feature

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

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

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

Changes

  • 0.1.9: added talk and OriginPro style

  • 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

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

Core symbols most depended-on inside this repo

set_style
called by 5
publib/publib.py
fix_style
called by 4
publib/publib.py
_get_lib
called by 3
publib/publib.py
_read_style
called by 2
publib/publib.py
_set_style
called by 1
publib/publib.py
_fix_style
called by 1
publib/publib.py
_get_style
called by 1
publib/publib.py

Shape

Function 11

Languages

Python100%

Modules by API surface

publib/publib.py7 symbols
publib/test/test_functions.py4 symbols

For agents

$ claude mcp add publib \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact