Skip to main content

a e s t h e t i c

Project description

a e s t h e t i c

Luke's matplotlib style sheets. See also John Garrett's SciencePlots.

Preferences include:

  • Avoid constantly repeating matplotlib calls to prettify plots.
  • Avoid DejaVu Sans as a default matplotlib font.
  • Avoid drawing right and top axis spines unless they provide function.
  • White on black reduces eye strain; make generating white on black figures easier using *_wob style sheets.

install

...via pip: pip install aesthetic

...via local clone: git clone git@github.com:lgbouma/aesthetic.git; cd aesthetic; pip install -e .

usage examples

for plot styles, see the test driver. the general syntax follows:

from aesthetic import set_style
set_style("clean")
set_style("clean_wob")
set_style("science")
set_style("science_wob")

So if you wanted to make four different versions of the same plot with responsive colors:

from aesthetic import set_style

import numpy as np, matplotlib.pyplot as plt, matplotlib as mpl
import matplotlib.colors as mcolors
from cycler import cycler

def set_colors(style):
    base = plt.rcParams['axes.prop_cycle'].by_key()['color']
    if '_wob' in style:
        inverse = [tuple(1 - v for v in mcolors.to_rgb(c)) for c in base]
        plt.rcParams['axes.prop_cycle'] = cycler('color', inverse)
    else:
        pass

def make_plot(style):
    x = np.linspace(0,10,1000)
    y = (x/100)**3 + 5*np.sin(x)
    _x, _y = np.arange(2, 8, 0.5), np.arange(2, 8, 0.5)

    set_colors(style)
    fig, ax = plt.subplots(figsize=(3,2.5))
    ax.plot(x, y, label=f'style: {style}')
    ax.plot(x, y+3)
    ax.plot(x, y+6)
    _yerr = np.abs(np.random.normal(2, 1, _x.size))
    c = 'k' if '_wob' not in style else 'w'
    ax.errorbar(_x, _y, yerr=_yerr, marker='o', elinewidth=0.5, lw=0, c=c, markersize=2)
    ax.update({
        'xlabel': r'x [units]',
        'ylabel': r'y [units]',
    })
    ax.legend(fontsize='small')
    return fig

if __name__ == '__main__':
    styles = ['clean', 'science', 'clean_wob', 'science_wob']
    for style in styles:
        set_style(style)
        fig = make_plot(style)
        fig.savefig(f'plot_{style}.png', bbox_inches='tight', dpi=400)
        mpl.rc_file_defaults()

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

aesthetic-0.7.tar.gz (222.2 kB view details)

Uploaded Source

File details

Details for the file aesthetic-0.7.tar.gz.

File metadata

  • Download URL: aesthetic-0.7.tar.gz
  • Upload date:
  • Size: 222.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for aesthetic-0.7.tar.gz
Algorithm Hash digest
SHA256 1c621880693bc4d81c9f3b15a1d9fd65f15893b203048e84b11eb9fc518e9124
MD5 63c15d91576016d7290a0f4bea963983
BLAKE2b-256 1eccd9517ab375f58ce2a935b443ba443e889231755f1a21836e7fdc5363e1f9

See more details on using hashes here.

Supported by

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