Skip to main content

A collection of matplotlib tuning scripts

Project description

This package defines two classes that hold common actions performed on matplotlib plots.

Installation

To install mpl_tune, run the following command: pip install mpl_tune

Usage

The package contains two classes:

  • FigSize to control to size and margins of figures
  • FigText to set properties (color, font size) on different elements of a figure

FigSize

The idea behind FigSize is to give margins in absolute values and let the code compute the relative values that are required by matplotlib. So that in case one want to resize a figure, one does not need to recalculate the margins to fit the new plot size. An example of usage is:

figsize = mpl_tune.FigSize()
figsize.set_size_h( 3.5 ) # Horizontal size of the figure, in inches
figsize.set_size_v( 3.0 ) # Vertical size of the figure, in inches
figsize.set_margin_left( 0.6 ) # Left margin, in inches
figsize.set_margin_bottom( 0.4 ) # Bottom margin, in inches
figsize.set_margin_right( 0.1 ) # Right margin, in inches
figsize.set_margin_top( 0.1 ) # Top margin, in inches

# Create the figure from the values set in the figsize object
fig = matplotlib.pyplot.figure( **figsize.get_figure_args() )
fig.subplots_adjust( **figsize.get_subplots_args() )

ax = fig.add_subplot( 1, 1, 1 )

# Use fig and ax to make your plot

In addition to the features shown above, the FigSize class can also handle multiple subplots in one figure and reserve space for color bars.

An example usage including those features is:

figsize = mpl_tune.FigSize()
figsize.set_size_h( 7.0 )
figsize.set_size_v( 5.0 )
figsize.set_nrows( 2 )
figsize.set_ncols( 2 )
figsize.set_margin_left( 0.6 )
figsize.set_margin_bottom( 0.4 )
figsize.set_margin_right( 0.1 )
figsize.set_margin_top( 0.1 )
figsize.set_spacing_h( 0.65 ) # Horizontal spacing between suplot in in inches; optional, defaults to the sum of left and right margins
figsize.set_spacing_v( 0.45 ) # Vertical spacing between suplot in in inches; optional, defaults to the sum of top and bottom margins
figsize.set_cbar_loc( "bottom" ) # Location of the color bar; can be "left", "right", "top" or "bottom"
figsize.set_cbar_width( 0.1 ) # Width of the color bar, in inches
figsize.set_cbar_pad( 0.45 ) # Padding between the color bar and the nearest axes, in inches

# Create the figure from the values set in the figsize object
fig = matplotlib.pyplot.figure( **figsize.get_figure_args() )
fig.subplots_adjust( **figsize.get_subplots_args() )

ax1 = fig.add_subplot( 2, 2, 1 )
ax2 = fig.add_subplot( 2, 2, 2 )
ax3 = fig.add_subplot( 2, 2, 3 )
ax4 = fig.add_subplot( 2, 2, 4 )

# Use fig and ax* to make your plot

if figsize.has_cbar():
	# Note, in the call below, "coll" represent a collection (or else) that is used to define the color bar
	cax = fig.add_axes( figsize.get_cbar_ax_spec() )
	cb = fig.colorbar( coll, orientation = figsize.get_cbar_orientation(), cax = cax )

FigText

The idea behind FigText is to set at the beginning the main foreground color of the plot and text size, and then to provide a few simple method to set these to the plot's elements.

An example of usage is:

usetex = True # or False

matplotlib.rc( "text", usetex = usetex )

figtext = mpl_tune.FigText( color = "black", size = "medium", tex = usetex )

# Create Figure and Axes objects, possibly with the help of FigSize

ax.set_xlabel( figtext.conv( "X axis label" ), **figtext.get_text_args() )
ax.set_ylabel( figtext.conv( "Y axis label" ), **figtext.get_text_args() )

figtext.set_axes( ax )

# If you have a Colorbar instance, you can use
figtext.set_cbar( cb )

# If you have a Legend instance, you can use
figtext.set_legend( legend )

The use of the conv() method will add the escaping sequences needed to run the text through the TeX (or mathtext) processor so that one does not need to run t

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

mpl_tune-0.1-py3.8.egg (13.5 kB view details)

Uploaded Source

mpl_tune-0.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file mpl_tune-0.1-py3.8.egg.

File metadata

  • Download URL: mpl_tune-0.1-py3.8.egg
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.0

File hashes

Hashes for mpl_tune-0.1-py3.8.egg
Algorithm Hash digest
SHA256 fec3596f67ff1a01adfe620261613f32f044cd63a62df326d01c64e08270f963
MD5 c3bb79bb4f80b8dfa2ef13546ee6fc01
BLAKE2b-256 dea967e0f3d6f71cffbf834ee7a218c1b9767eb224a09e055d620626a2dd8034

See more details on using hashes here.

Provenance

File details

Details for the file mpl_tune-0.1-py3-none-any.whl.

File metadata

  • Download URL: mpl_tune-0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.0

File hashes

Hashes for mpl_tune-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88741dd05b3065df9cc8376458165ef6448692662bfafc567b4af9412448dc06
MD5 6d7bfc8b0f6b209a4a778ba98ec7cde5
BLAKE2b-256 5e50e0c22553220eec4394f84683c42b4e51bdc84e6ced5b7d3303bb07dc8207

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