mcplot: plotting class, colormaps and helper functions for plotting.
Project description
A Python package with a plotting class and routines for publication-ready graphics.
About mcplot
mcplot provides a class that combines methods to easily produce publication-ready graphics on light or black background. It includes a large number of colormaps collected from different sources. There are a number of functions that help to position plots, number plot panels, or write text on a graph.
The complete documentation of mcplot is available at:
Installation
The easiest way to install is via pip:
python -m pip install mcplot
or via conda:
conda install -c conda-forge mcplot
- Requirements
Calling a plotting script from the command line
mcplot provides a class that has methods for opening and closing different plotting backends, setting layout options, as well as having a command line interface. A most basic example is using the method plot_test, which just plots two sinusoidal curves. A file mcplot_test.py could be:
# file: mcplot_test.py
from mcplot import mcPlot
if __name__ == '__main__':
iplot = mcPlot(desc='Test mcPlot',
argstr='No argument wanted')
iplot.plot_test()
iplot.close()
This script mcplot_test.py can be called on the command line. ‘-h’ gives a short help:
python mcplot_test.py -h
gives the help message:
usage: mcplot_test.py [-h] [-o plotname] [-s] [-t outtype] [-u]
[-w] [--dpi number] [--transparent] [args ...]
Test mcPlot
positional arguments:
args No argument wanted
options:
-h, --help show this help message and exit
-o plot_filename, --output plot_filename,
-p plot_filename, --plotname plot_filename
Name of plot output file for types pdf, html,
d3, or hvplot, and name basis for type png
(default: class_mcplot).
-s, --serif Use serif font; default sans serif.
-t outtype, --type outtype
Output type is pdf, png, html, d3, or hvplot
(default: open screen windows).
-u, --usetex Use LaTeX to render text in pdf, png and html.
-w, --white White lines on transparent or black background;
default: black lines on transparent or
white background.
--dpi number Dots Per Inch (DPI) for non-vector output types or
rasterized maps in vector output (default: 300).
--transparent Transparent figure background
(default: black or white).
--font name Font name or LaTeX package name
(default: DejaVuSans or DejaVuSerif (serif) and
MyriadPro or ComputerModern (serif) if --usetex
python mcplot_test.py
opens a standard Matplotlib plotting window with the test plot.
python mcplot_test.py -t pdf -o test1.pdf
writes the plot into the PDF file test1.pdf using the sans-serif font DejaVuSans that comes with Matplotlib. It will use the serif font DejaVueSerif with the command line option -s. It will use LaTeX to render text with the -u option. -u -s uses LaTeX’s standard Computer Modern font. It uses MyriadPro as sans-serif font in LaTeX, which must be installed (see section Myriad Pro).
By default, mcPlot plots onto a DIN A4 page, which facilitates choices of font sizes, etc. The output can easily be cropped with the utility pdfcrop which can be acquired from CTAN. The standard subplots are on a 2x3 grid. The plot will be tightly cropped if the output type is png. Plot resolution can be set for png as well (–dpi) with standard being 300 dpi. PNG plots can have transparent background (–transparent), for example to use in presentations.
The command line switch -w swaps foreground and backgroud colors, i.e. uses white lines on black background. This is used if you do presentations with black background.
In summary, the standard command line options allow to use the same script to design a plot using plotting windows on screen, produce the publication ready plots in a PDF file (-t, -o, -u options), and make the same plot with dark background for presentations (-t, -o, -u, -w options).
Using the plotting class
The class mcPlot can be extended. One normally would have at least a method to read data from a file and a method that produces a plot. This could give a script such as:
# file: mcplot_basic.py
import numpy as np
from mcplot import mcPlot
class myPlot(mcPlot):
def read_data(self):
# reading one file would use self.cargs[0] such as
# self.dat = np.loadtxt(self.cargs[0])
self.dat = np.arange(100)
def plot_fig_1(self):
import matplotlib.pyplot as plt
# make axes
fig = plt.figure()
ax = fig.add_subplot(3, 2, 1)
# plot
xx = self.dat / self.dat.size * 4. * np.pi
line1 = ax.plot(xx, np.sin(xx))
plt.setp(line1, linestyle='-', linewidth=self.lw,
marker='', color=self.lcol1)
# show plot or write in file
self.plot_save(fig)
if __name__ == '__main__':
# open plot
iplot = myPlot(desc='A basic plot')
# read data
iplot.read_data()
# plot
iplot.plot_fig_1()
# close plot and possible output file
iplot.close()
The script could be called giving the name(s) of (an) input file(s) on the command line, which is then accessible through self.cargs:
python mcplot_basic.py -t png -o basic. input.csv
Every time self.plot_save(fig) is called, a figure is written to the output file. A PDF file can have multiple pages. For PNG files, only the start of the output files is given (here basic.) and will be extended by f’{start}{self.ifig:04d}.png’. The example would give the outputfile basic.0001.png.
See the complete documentation of mcplot at: https://mcuntz.github.io/mcplot/
License
mcplot is distributed under the MIT License. See the LICENSE file for details.
Copyright (c) 2021- Matthias Cuntz
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcplot-2.2.tar.gz.
File metadata
- Download URL: mcplot-2.2.tar.gz
- Upload date:
- Size: 191.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77116499a09cd1ccdb6ce77a85a11949f0d2c17cf9a3c2d5d0181d6287ceb656
|
|
| MD5 |
936a166ac606e8e91d7462b51deb0191
|
|
| BLAKE2b-256 |
38b15bff99eba7fa8e04fe5fce9709b958c0e77b4d711f7437c809b81ccd52c5
|
Provenance
The following attestation bundles were made for mcplot-2.2.tar.gz:
Publisher:
main.yml on mcuntz/mcplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcplot-2.2.tar.gz -
Subject digest:
77116499a09cd1ccdb6ce77a85a11949f0d2c17cf9a3c2d5d0181d6287ceb656 - Sigstore transparency entry: 226239818
- Sigstore integration time:
-
Permalink:
mcuntz/mcplot@8ac2c16a8456101e821a89961ae562fbb39e4634 -
Branch / Tag:
refs/tags/v2.2 - Owner: https://github.com/mcuntz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@8ac2c16a8456101e821a89961ae562fbb39e4634 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcplot-2.2-py3-none-any.whl.
File metadata
- Download URL: mcplot-2.2-py3-none-any.whl
- Upload date:
- Size: 188.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d73b6bb1ad36946449a5fca014c41a4f797b780d41b063199c31d122f4f1d55
|
|
| MD5 |
54e5b3443de3895f93f54bbe795170db
|
|
| BLAKE2b-256 |
66ce9ab3efeb45620cf7cf0a5eb73e50e39fda644ae0b623309da0c67f462adf
|
Provenance
The following attestation bundles were made for mcplot-2.2-py3-none-any.whl:
Publisher:
main.yml on mcuntz/mcplot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcplot-2.2-py3-none-any.whl -
Subject digest:
8d73b6bb1ad36946449a5fca014c41a4f797b780d41b063199c31d122f4f1d55 - Sigstore transparency entry: 226239832
- Sigstore integration time:
-
Permalink:
mcuntz/mcplot@8ac2c16a8456101e821a89961ae562fbb39e4634 -
Branch / Tag:
refs/tags/v2.2 - Owner: https://github.com/mcuntz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@8ac2c16a8456101e821a89961ae562fbb39e4634 -
Trigger Event:
push
-
Statement type: