Skip to content

scifont: Publication-ready, reproducible, and editable figures for Matplotlib.

License

Notifications You must be signed in to change notification settings

studentiz/scifont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scifont

中文 | English

Publication-ready Matplotlib figures with editable text and journal-compliant fonts.

The Problem

As a researcher creating figures for publication, you've likely encountered these issues:

  1. Font inconsistencies across environments: Your figures look perfect on your local machine (Windows, macOS, or Linux), but when you run the same code on a server, in a Docker container, or in CI/CD pipelines, the fonts are missing. Arial and Times New Roman aren't available everywhere, causing your figures to break or look different.

  2. Uneditable text in vector graphics software: You export your figure as PDF or SVG for final editing in Adobe Illustrator or Inkscape, only to discover that the text is converted to uneditable paths. Fixing a typo or adjusting labels means redrawing the entire figure.

  3. Manual journal style configuration: Each journal has specific font and size requirements. You spend hours tweaking Matplotlib's rcParams to match Nature's guidelines, then repeat the entire process when submitting to Science or IEEE.

The Solution

scifont solves all three problems with one line of code:

import scifont
scifont.use('nature')  # That's it!

What it does:

  • ✅ Automatically uses system fonts (Arial, Helvetica, Times New Roman) when available, seamlessly falls back to metric-compatible open-source fonts (Arimo/Tinos) when system fonts are missing
  • ✅ Configures Matplotlib to export editable text in PDF/SVG files, so you can fix typos in Adobe Illustrator without redrawing
  • ✅ Provides one-line configuration for Nature, Science, Cell, and IEEE style guidelines—no more manual rcParams tweaking

🚀 Key Features

  • Smart Font Selection: Prioritizes system fonts (Arial, Helvetica, Times New Roman) when available. Automatically falls back to bundled open-source fonts (Arimo, Tinos) when system fonts are missing.

  • Metric-Compatible Fonts: We bundle Arimo and Tinos (Apache 2.0 Licensed) as alternatives to Arial and Times New Roman. They have identical character widths and spacing, so your layout stays exactly the same.

  • Editable Vector Graphics: Automatically configures Matplotlib to export PDFs as Type 42 objects and SVGs as <text> tags. Text remains editable in Adobe Illustrator, Inkscape, and CorelDRAW.

  • Journal Presets: One-line configuration for Nature, Science, Cell, and IEEE standards.

  • Publication-Ready Styling: Automatically applies scientific publication best practices, including inward-facing ticks, appropriate line widths, and clean axis styling for professional-looking figures.

📦 Installation

pip install --upgrade scifont

Or install from source:

git clone https://github.com/studentiz/scifont.git
cd scifont
pip install .

⚡ Quick Start

import matplotlib.pyplot as plt
import scifont

# Apply journal style
scifont.use('nature')

# Plot as usual
plt.figure(figsize=(4, 3))
plt.plot([1, 2, 3], [4, 5, 6], label='Data')
plt.title("Editable Text in Nature Style")
plt.xlabel("Time (s)")
plt.ylabel("Velocity (m/s)")
plt.legend()

# Save - text will be editable in Adobe Illustrator!
plt.tight_layout()
plt.savefig("figure.pdf")
plt.savefig("figure.svg")

📖 Supported Journal Styles

Style Font Family Primary Font Fallback Font Base Size Target Journals
'nature' Sans-serif Arial/Helvetica Arimo 7 pt Nature, Nature Comms, Scientific Reports
'cell' Sans-serif Arial/Helvetica Arimo 8 pt Cell, Molecular Cell, Neuron
'science' Sans-serif Arial/Helvetica Arimo 8 pt Science, Science Advances
'ieee' Serif Times New Roman/Times Tinos 8 pt IEEE Transactions, Phys. Rev. Lett.

Note: You can override any setting using plt.rcParams after calling scifont.use().

🎯 What scifont Does (and Doesn't Do)

What scifont solves:

  • ✅ Font consistency across all platforms (Windows, macOS, Linux) and environments (local machines, servers, Docker containers)
  • ✅ Editable text in PDF/SVG files—fix typos in Adobe Illustrator without redrawing
  • ✅ Journal-compliant font and size settings for major journals
  • ✅ True cross-platform compatibility—same code works everywhere
  • ✅ Professional figure styling—automatic configuration of ticks, borders, and line widths for publication-ready appearance

What scifont doesn't do:

  • ❌ It's not a design tool—you still need to adjust layout, colors, and aesthetics
  • ❌ It won't automatically make your figures publication-ready—you'll still need to fine-tune spacing, legends, and annotations
  • ❌ It's a configuration helper, not a replacement for manual work

Think of it as a solid foundation. One scifont.use('nature') call replaces dozens of manual rcParams tweaks, but you're still in full control to customize everything afterward.

🛡️ Why Bundle Open-Source Fonts?

Arial and Times New Roman are proprietary fonts owned by Monotype. It's illegal to bundle them in a Python package without a costly license. Also, relying on system fonts alone causes inconsistencies—a plot rendered on Windows or macOS (with Arial) looks different on Linux servers or Docker containers (without Arial).

Our solution: We bundle open-source fonts as fallback fonts. They're:

  • Free to use, bundle, and distribute: All bundled fonts use permissive open-source licenses
  • Metric-compatible: Identical character widths and spacing to their proprietary counterparts. No layout changes when switching fonts.

Bundled Fonts and Licenses

Font License Purpose Notes
Arimo Apache License 2.0 Sans-serif fallback for Arial/Helvetica Developed by Steve Matteson for Google. Metric-compatible with Arial.
Tinos Apache License 2.0 Serif fallback for Times New Roman/Times Developed by Steve Matteson for Google. Metric-compatible with Times New Roman.
Noto Sans SC SIL Open Font License (OFL) 1.1 Chinese font fallback Developed by Google and Adobe. Supports Simplified Chinese characters.

All bundled fonts are freely available for commercial and non-commercial use, modification, and distribution under their respective licenses.

🔧 Technical Details

By default, scifont.use() applies these Matplotlib settings:

plt.rcParams['pdf.fonttype'] = 42  # Embed TrueType fonts (editable)
plt.rcParams['ps.fonttype'] = 42
plt.rcParams['svg.fonttype'] = 'none'  # Don't convert text to paths

This ensures compatibility with Adobe Illustrator, CorelDRAW, and Inkscape.

License

The scifont code is distributed under the MIT License.

The bundled fonts are distributed under their respective open-source licenses:

  • Arimo and Tinos: Apache License, Version 2.0
  • Noto Sans SC: SIL Open Font License (OFL) 1.1

Disclaimer

Font Licensing: All bundled fonts (Arimo, Tinos, and Noto Sans SC) are open-source and freely available for use, modification, and distribution under their respective licenses. However, users are responsible for ensuring compliance with these licenses in their specific use cases.

No Warranty: This software is provided "as is" without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement.

Political Neutrality: The bundled fonts (particularly Noto Sans SC) are technical tools designed for text rendering and do not represent any political stance or affiliation. Users should ensure compliance with local laws and regulations when using these fonts in their jurisdictions.

About

scifont: Publication-ready, reproducible, and editable figures for Matplotlib.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages