API Reference
Main Functions
Figure and Subplot Creation
- pubplotlib.figure(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None, journal=None, **kwargs)[source]
Create a figure with style-appropriate dimensions.
- pubplotlib.subplots(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None, journal=None, **kwargs)[source]
Create subplots with style-appropriate dimensions.
Style Management
- pubplotlib.set_style(style=None)[source]
Apply the style. Does nothing if already set.
- pubplotlib.set_journal(journal=None)[source]
Apply the journal style. Does nothing if already set.
- pubplotlib.get_style(style=None)[source]
Return a Style instance (from string or directly).
- pubplotlib.available_styles()[source]
Return a list of available styles.
- pubplotlib.restore()[source]
Restore matplotlib’s default style.
Figure Sizing
- pubplotlib.setup_figsize(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None)[source]
Return (width, height) in inches for the style.
Axis Formatting
- pubplotlib.set_ticks(ax=None, minor=True, direction='in', right=True, top=True, major_length=3.5, minor_length=1.75)[source]
Configure tick appearance on axes.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to configure. If None, uses current axes.
minor (bool, default True) – Whether to show minor ticks.
direction ({'in', 'out', 'inout'}, default 'inout') – Direction of tick marks.
right (bool, default False) – Whether to show ticks on right y-axis.
top (bool, default False) – Whether to show ticks on top x-axis.
major_length (float, default 3.5) – Length of major ticks.
minor_length (float, default 1.75) – Length of minor ticks.
- pubplotlib.set_formatter(ax=None, low=0.01, high=100, axis='both')[source]
Apply custom formatting to axis that preserves matplotlib’s tick placement.
Uses decimal notation for values between low and high, and scientific notation outside this range.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to format. If None, uses current axes.
low (float, default 0.01) – Lower bound for decimal notation.
high (float, default 100) – Upper bound for decimal notation.
axis ({'x', 'y', 'both'}, default 'both') – Which axes to format.
Examples
>>> fig, ax = plt.subplots() >>> ax.loglog(x, y) >>> set_formatter(ax, low=0.01, high=100)
Style Namespace
The pplt.style object provides a matplotlib-like interface:
- class pubplotlib.pubplotlib._StyleManager[source]
Manager for style operations, providing a matplotlib-like interface.
Mimics matplotlib.style.use() syntax while integrating with PubPlotLib’s style framework.
- use(style=None)[source]
Apply a style globally. Mimics matplotlib.style.use() syntax.
Examples
>>> pplt.style.use('aanda')
- available()[source]
Return list of available styles.
- Returns:
Names of all available styles.
- Return type:
Examples
>>> pplt.style.available() ['aanda', 'apj', 'presentation']
- get(style=None)[source]
Get a Style instance.
- Parameters:
style (str or Style, optional) – Name of the style or a Style instance. If None, returns the current active style.
- Returns:
The requested Style instance.
- Return type:
Examples
>>> s = pplt.style.get('aanda') >>> print(s.onecol, s.twocol)
Style Objects
Constants
- pubplotlib.golden = 1.618033988749895
Convert a string or number to a floating point number, if possible.
- pubplotlib.pt = 0.013837000138370002
Convert a string or number to a floating point number, if possible.
- pubplotlib.cm = 0.39370078740157477
Convert a string or number to a floating point number, if possible.
Formatter Utilities
- class pubplotlib.formatter.ScalarFormatter(low=0.001, high=1000.0, **kwargs)[source]
Custom scalar formatter with configurable scientific notation bounds.
Shows decimal notation for values between low and high, and scientific notation outside this range.
Style Builder Module
- pubplotlib.stylebuilder.check_fonts(font_list=None, verbose=True)[source]
Check if the required fonts are available to Matplotlib. Prints a summary and returns a dict {font_name: found_bool}.
- pubplotlib.stylebuilder.build_builtin_styles(overwrite=False)[source]
Build and write the default built-in styles YAML file with standard styles (e.g., journals). Overwrites the file if overwrite=True.
- pubplotlib.stylebuilder.remove_style(name)[source]
Remove a user style from the user YAML registry and delete its style file. Built-in styles cannot be removed.
- Parameters:
name (str) – The name of the style to remove.
Formatter Module
- class pubplotlib.formatter.LogFormatterSciNotation(low=0.001, high=1000.0, **kwargs)[source]
Bases:
LogFormatterSciNotationCustom logarithmic formatter with configurable scientific notation bounds.
Shows decimal notation for values between low and high, and scientific notation outside this range.
- class pubplotlib.formatter.ScalarFormatter(low=0.001, high=1000.0, **kwargs)[source]
Bases:
ScalarFormatterCustom scalar formatter with configurable scientific notation bounds.
Shows decimal notation for values between low and high, and scientific notation outside this range.
- class pubplotlib.formatter.SelectiveFormatter(tick_labels, *args, **kwargs)[source]
Bases:
LogFormatterSciNotationFormatter that only displays labels for specified tick values.
Useful for showing labels only on major ticks while keeping minor ticks unlabeled.
- Parameters:
tick_labels (array-like) – The numerical values for which labels should be shown.
*args – Additional arguments passed to LogFormatterSciNotation.
**kwargs – Additional arguments passed to LogFormatterSciNotation.
Examples
>>> import matplotlib.pyplot as plt >>> import matplotlib.ticker as ticker >>> >>> # Setup selective formatting >>> tickvalues = generate_log_ticks(0.01, 100) >>> major_ticks = generate_powers_of_10_ticks(0.01, 100) >>> minor_ticks = filter_major_ticks(tickvalues, major_ticks) >>> formatter = SelectiveFormatter(major_ticks) >>> >>> # Apply to axes >>> fig, ax = plt.subplots() >>> ax.xaxis.set_major_formatter(formatter) >>> ax.xaxis.set_major_locator(ticker.FixedLocator(major_ticks)) >>> ax.xaxis.set_minor_locator(ticker.FixedLocator(minor_ticks))
- pubplotlib.formatter.set_formatter(ax=None, low=0.01, high=100, axis='both')[source]
Apply custom formatting to axis that preserves matplotlib’s tick placement.
Uses decimal notation for values between low and high, and scientific notation outside this range.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to format. If None, uses current axes.
low (float, default 0.01) – Lower bound for decimal notation.
high (float, default 100) – Upper bound for decimal notation.
axis ({'x', 'y', 'both'}, default 'both') – Which axes to format.
Examples
>>> fig, ax = plt.subplots() >>> ax.loglog(x, y) >>> set_formatter(ax, low=0.01, high=100)
Tick Setter Module
- pubplotlib.ticksetter.set_ticks(ax=None, minor=True, direction='in', right=True, top=True, major_length=3.5, minor_length=1.75)[source]
Configure tick appearance on axes.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to configure. If None, uses current axes.
minor (bool, default True) – Whether to show minor ticks.
direction ({'in', 'out', 'inout'}, default 'inout') – Direction of tick marks.
right (bool, default False) – Whether to show ticks on right y-axis.
top (bool, default False) – Whether to show ticks on top x-axis.
major_length (float, default 3.5) – Length of major ticks.
minor_length (float, default 1.75) – Length of minor ticks.
Complete Module Reference
- pubplotlib.setup_figsize(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None)[source]
Return (width, height) in inches for the style.
- pubplotlib.figure(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None, journal=None, **kwargs)[source]
Create a figure with style-appropriate dimensions.
- pubplotlib.subplots(style=None, twocols=False, fullpage=False, width_fraction=1.0, height_ratio=None, journal=None, **kwargs)[source]
Create subplots with style-appropriate dimensions.
- pubplotlib.set_formatter(ax=None, low=0.01, high=100, axis='both')[source]
Apply custom formatting to axis that preserves matplotlib’s tick placement.
Uses decimal notation for values between low and high, and scientific notation outside this range.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to format. If None, uses current axes.
low (float, default 0.01) – Lower bound for decimal notation.
high (float, default 100) – Upper bound for decimal notation.
axis ({'x', 'y', 'both'}, default 'both') – Which axes to format.
Examples
>>> fig, ax = plt.subplots() >>> ax.loglog(x, y) >>> set_formatter(ax, low=0.01, high=100)
- pubplotlib.set_ticks(ax=None, minor=True, direction='in', right=True, top=True, major_length=3.5, minor_length=1.75)[source]
Configure tick appearance on axes.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to configure. If None, uses current axes.
minor (bool, default True) – Whether to show minor ticks.
direction ({'in', 'out', 'inout'}, default 'inout') – Direction of tick marks.
right (bool, default False) – Whether to show ticks on right y-axis.
top (bool, default False) – Whether to show ticks on top x-axis.
major_length (float, default 3.5) – Length of major ticks.
minor_length (float, default 1.75) – Length of minor ticks.