Skip to main content

Neatly format Matplotlib scientific plots

Project description

neat-sciplots

Neatly format Matplotlib scientific plots

neat-sciplots is a beta Python package that neatly formats scientific plots created with Matplotlib in a user-friendly, yet highly customizable way. It makes typesetting in LaTeX possible and comes with several methods that makes plotting more straightforward and less cluttered, without sacrificing full control over plot settings. Two examples plots created with neat-sciplots is shown below.

example_plot example_plot

The neat-sciplots package was developed by Andreas Führ in May 2021.

Installation and getting started

To install the latest release from PyPI, execute the following command:

pip install neat-sciplots

To install the latest commit, please use the the following command:

pip install git+https://github.com/andreasfuhr/neat-sciplots.git



Formatting plots in Matplotlib is based on a functional with-statement context. A MWE can be demonstrated as follows:

import matplotlib.pyplot as plt
import sciplot

# Define x and y...

with sciplot.style():
    plt.plot(x, y)
    plt.show()

If a LaTeX distribution is not available, use_latex=False must be passed as an argument to sciplot.style(). For demonstrations of plotting that covers all packages features, see either example_plots.py in the example_plots directory.

Overview

Key Features:

  • User-friendly. A style context manager is used for all Matplotlib related user code and can be passed several arguments to alter the look of the plot, such as:
    • LaTeX typesetting
    • serif or sans serif font
    • dark mode
    • locale string (for correct decimal separator etc.)
  • Implements LaTeX kernel for typesetting plots. A versatile LaTeX preamble is included that is specifically created and optionally editable for mathematics- and physics-oriented papers, theses and presentations. Both the siunitx and physics LaTeX packages are for example included by default in the parameter settings.
  • Easy customization. Most settings have been moved to parameters files, which are imported to the context manager and configured with matplotlibrc. The user is encouraged to edit these accessible and highly readable YAML parameters files, whom can be found with the sciplot.get_paramters_dir() method.
  • Includes a set of useful methods relevant during plotting:
    • sciplot.set_size_cm() for setting figure sizes in centimeters
    • sciplot.set_legend() for customizing the content and position of plot legends
    • sciplot.get_color_lst() for extracting a list of colors of specified length and from a given Seaborn colormap
    • sciplot.save_time_stamped_figure for saving plots in an easy manner with time stamped file names

Disadvantages:

  • Slow. LaTeX figures can take quite some time to compile. Loading the parameters is however not known from experience to be time consuming.
  • Only compatible with Python 3.7 and later. The 3.3.4 version of Matplotlib fixes several bugs that directly solves some earlier issues with this package.

It should be noted that although this package is in many ways similar to [1], which is a recommended alternative approach, neat-sciplots has been independently developed and has a multitude of structural and functional differences.

Citing neat-plots

To cite this Python package, please use the following BibTeX citation:

@article{neat-sciplots,
  author       = {Andreas H. Führ},
  title        = {{andreasfuhr/neat-sciplots}},
  month        = may,
  year         = 2021,
  version      = {0.7.7},
}

Note that under the current license, citing this package is not necessary. The creator will however be happy and thankful for any recognition.

Future improvements

The package is still in its infancy and is planned to be expanded in features and configurability. Here is a list of what is in the pipeline:

  • Documentation of source code
  • Instructions on how to install a local LaTeX distribution
  • Making it possible to choose LaTeX fonts. As of currently, Computer Modern Roman and Computer Modern Roman Sans Serif are the only two font options for both text and mathematical notation.
  • Test suite for further code development
  • Include example plots in documentation
  • Write instructions on how to use the package
  • Add more themes. Let sciplot.style() take the argument theme=str or theme=List[str].

Table of proposed themes:

Name of theme Priority Background color Font Seaborn colormap Figure size
default1 high white CMR Sans Serif cubehelix -
dark high black - - -
antique low white Garamond TBD -
ieee_column medium white ?2 TBD 88 mm3
ieee_page low white ?2 TBD 181 mm3

1: Initialised at start of context.

2: One of the following Open Type fonts are suggested to be used: Times New Roman, Helvetica, Arial, Cambria or Symbol [2].

3: See [2] for a description of sizes that graphics should be.

References

[1] J.D. Garrett and H. Peng, garrettj403/SciencePlots, ver. 1.0.7. Zenodo, Feb. 2021. [Online]. doi: 10.5281/zenodo.4106649

[2] "Preparation of papers for IEEE Transactions and Journals (December 2013)," in IEEE Transactions on Consumer Electronics, vol. 63, no. 1, pp. c3-c3, February 2017, doi: 10.1109/TCE.2017.7932035

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

neat-sciplots-0.7.7.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

neat_sciplots-0.7.7-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file neat-sciplots-0.7.7.tar.gz.

File metadata

  • Download URL: neat-sciplots-0.7.7.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for neat-sciplots-0.7.7.tar.gz
Algorithm Hash digest
SHA256 49f23f199c65530c3d775eede5b77e03db94c3d08306e3ee63bd596ec7454411
MD5 a73c8bf031d12ea07831cd1e6cab3f1c
BLAKE2b-256 c37c6caf4b4d1c1cb97796d109b4bf6298404cfb12a0f795105cc8931c50e157

See more details on using hashes here.

Provenance

File details

Details for the file neat_sciplots-0.7.7-py3-none-any.whl.

File metadata

  • Download URL: neat_sciplots-0.7.7-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for neat_sciplots-0.7.7-py3-none-any.whl
Algorithm Hash digest
SHA256 5137951b5eecb001c30d777a0ae59d0f618cf08d3d2a6142e51afdde3656c2ce
MD5 e2ec24468696cccc968e1618ea8f8836
BLAKE2b-256 26a655ac322d3f53047200069672020629b1c9c0a5c8965d70c1024abc56eb3f

See more details on using hashes here.

Provenance

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