Master Publication-Quality Plots in Python with Matplotlib, SciencePlots, and Proplot

This tutorial walks through creating high‑quality scientific figures in Python by customizing Matplotlib globally, removing spines, adjusting tick parameters, adding axis labels, and then demonstrates the use of the SciencePlots and Proplot libraries for consistent styling and advanced layout options.

Model Perspective
Model Perspective
Model Perspective
Master Publication-Quality Plots in Python with Matplotlib, SciencePlots, and Proplot

Python‑Matplotlib

import numpy as np
import matplotlib.pyplot as plt
# Build data

def model(x, p):
    return x ** (2 * p + 1) / (1 + x ** (2 * p))

x = np.linspace(0.75, 1.25, 201)
fig, ax = plt.subplots(figsize=(4,3), dpi=200)
for p in [10, 15, 20, 30, 50, 100]:
    ax.plot(x, model(x, p), label=p)

Set Global Chart Property Variables

For projects that generate many figures, you can change common attributes such as font, font size, line width, and tick size before plotting:

plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.size'] = 18
plt.rcParams['axes.linewidth'] = 2

Remove Axis Spines

Some publication styles require hiding the top and right spines:

ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)

Tick Parameters

Adjust tick length, width, direction, and add minor ticks:

# Add minor ticks
from matplotlib.pyplot import MultipleLocator
fig, ax = plt.subplots(figsize=(4,3), dpi=200)

yminorLocator = MultipleLocator(.25/2)  # y‑axis minor tick interval
xminorLocator = MultipleLocator(.25/2)  # x‑axis minor tick interval
ax.yaxis.set_minor_locator(yminorLocator)
ax.xaxis.set_minor_locator(xminorLocator)

# Major tick settings
ax.tick_params(which='major', length=5, width=1.5, direction='in', top='on', right='on')
# Minor tick settings
ax.tick_params(which='minor', length=3, width=1, direction='in', top='on', right='on')

Axis Labels

Add descriptive axis labels with custom font size and padding:

ax.set_xlabel('Voltage (mV)', fontsize=13, labelpad=5)
ax.set_ylabel('Current ($\mu$A)', fontsize=13, labelpad=5)

Summary – Apply All Settings

Combine the global settings, spine removal, tick configuration, labels, grid, legend, title, and annotation into a single script:

plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.size'] = 12
plt.rcParams['axes.linewidth'] = 1
plt.rcParams['legend.title_fontsize'] = 9

fig, ax = plt.subplots(figsize=(4,3), dpi=200)
colors = ["#0073C2", "#EFC000", "#868686", "#CD534C", "#7AA6DC", "#003C67"]
for p, c in zip([10, 15, 20, 30, 50, 100], colors):
    ax.plot(x, model(x, p), color=c, label=p)

# Minor ticks
yminorLocator = MultipleLocator(.25/2)
xminorLocator = MultipleLocator(.25/2)
ax.yaxis.set_minor_locator(yminorLocator)
ax.xaxis.set_minor_locator(xminorLocator)

# Tick parameters
ax.tick_params(which='major', length=5, width=1.5, direction='in', top='on', right='on')
ax.tick_params(which='minor', length=3, width=1, direction='in', top='on', right='on')

# Axis labels
ax.set_xlabel('Voltage (mV)', fontsize=13, labelpad=5)
ax.set_ylabel('Current ($\mu$A)', fontsize=13, labelpad=5)

# Grid, legend, title, annotation
ax.grid(which='major', ls='--', alpha=.8, lw=.8)
ax.legend(fontsize=8, loc='upper left', title='Order')
ax.set_title('Default Plot Style Of Matplotlib', fontsize=14, pad=10)
ax.text(.87, .06, '
Visualization by DataCharm', transform=ax.transAxes,
        ha='center', va='center', fontsize=5)

SciencePlots Library

SciencePlots is a Python package for scientific figure styling.

Installation: pip install SciencePlots The package provides three main types of configuration files:

Theme files (e.g., "science", "ieee", "scatter") that control figure size, resolution, font choices, line styles, and marker sizes.

Color palettes (e.g., "bright", "high-vis") that change curve colors.

Grid styles that add predefined grid settings.

Two typical usage patterns:

Apply a style globally in the current script:

import matplotlib.pyplot as plt
plt.style.use('science')  # use the Science theme

Note: Using the global style may sometimes cause unexpected figure size ratios.

Apply styles locally with a context manager:

# Second method
with plt.style.context(['ieee', 'grid']):
    x = np.linspace(0.0, 2.0)
    y = np.sin(x)
    plt.plot(x, y, label="Line1")
    plt.plot(x, 2*y, label="Line2")
    plt.plot(x, 3*y, label="Line3")
    plt.plot(x, 4*y, label="Line4")
    plt.plot(x, 2.2*y, label="Line5")
    plt.autoscale(tight=True)
    plt.legend(title='Order', edgecolor='k')
    plt.show()

Proplot

Installation:

pip install proplot
conda install -c conda-forge proplot

Example of creating a styled figure with Proplot:

import proplot as plot
fig, ax = plot.subplots(figsize=(4,3.5), dpi=100)
for p in [10, 15, 20, 30, 50, 100]:
    ax.plot(x, model(x, p), label=p)
ax.format(
    title='Example Of Proplot Plot Style',
    abc=True, abcloc='ur', abcstyle='(A)',
    xlabel='Voltage (mV)', ylabel='Current ($\mu$A)',
    xtickdir='in', ytickdir='in',
    xtickloc='both', ytickloc='both',
    xgridminor=False, ygridminor=False)
ax.legend(ncols=1)

References

https://blog.csdn.net/Z987421/article/details/122057801

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonMatplotlibPlot StylingProplotSciencePlots
Model Perspective
Written by

Model Perspective

Insights, knowledge, and enjoyment from a mathematical modeling researcher and educator. Hosted by Haihua Wang, a modeling instructor and author of "Clever Use of Chat for Mathematical Modeling", "Modeling: The Mathematics of Thinking", "Mathematical Modeling Practice: A Hands‑On Guide to Competitions", and co‑author of "Mathematical Modeling: Teaching Design and Cases".

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.