SciencePlots Documentation

repository·master·Indexed 27 days ago

https://github.com/garrettj403/scienceplots

A collection of Matplotlib styles designed for scientific figures in academic papers, presentations, and theses. Includes specialized styles for IEEE and Nature, color-blind safe color cycles, and support for CJK languages. Requires Latex for full functionality.

Tokens
821
Snippets
2
Records
5
Agent score
44%

What's inside SciencePlots

  1. Install SciencePlots

    master

    You can install SciencePlots using pip, conda, or by installing directly from GitHub.

    Requirements:

    • Latex: SciencePlots requires Latex to be installed on your system.
    • CJK Fonts: If you intend to use Chinese, Japanese, or Korean fonts, you must install them separately.
    # Install latest release from PyPI
    pip install SciencePlots
    
    # Install latest release using Conda
    conda install -c conda-forge scienceplots
    
    # Install latest commit from GitHub
    pip install git+https://github.com/garrettj403/SciencePlots
    
    # Clone and install from a local copy
    git clone https://github.com/garrettj403/SciencePlots.git
    cd SciencePlots
    pip install -e .
  2. Use SciencePlots styles in Matplotlib

    master

    To use SciencePlots, you must import scienceplots at the top of your script before calling plt.style.use().

    Apply a single style

    Use plt.style.use('science') to apply the primary scientific style.

    Combine multiple styles

    You can cascade styles by passing a list. Later styles in the list will override parameters from earlier ones. For example, combining science with ieee configures the plot for IEEE paper requirements (column width, fontsizes, etc.).

    Use a style temporarily

    Use a context manager to apply a style only to a specific block of code.

    import matplotlib.pyplot as plt
    import scienceplots
    
    # Apply the primary style
    plt.style.use('science')
    
    # Combine styles (ieee overrides science)
    plt.style.use(['science', 'ieee'])
    
    # Use a style temporarily via context manager
    with plt.style.context('science'):
        plt.figure()
        plt.plot(x, y)
        plt.show()
  3. Use Color Cycles in SciencePlots

    master

    SciencePlots includes several color cycles for different visualization needs:

    • bright: A color-blind safe color cycle.
    • high-vis: A high-visibility color cycle.
    • discrete-rainbow-<n>: Paul Tol's discrete rainbow color sets, where <n> is the number of unique colors (ranging from 1 to 23). For example, discrete-rainbow-15 provides 15 colors.
  4. Support for CJK and Other Languages

    master

    SciencePlots supports various languages including Traditional Chinese, Simplified Chinese, Japanese, Korean, Russian, and Turkish.

    To use Traditional Chinese, you can use a combination like science + no-latex + cjk-tc-font. Note that CJK fonts must be installed separately on your system.

  5. Academic Journal Styles

    master

    SciencePlots provides specialized styles for specific publication formats:

    • IEEE: Use ['science', 'ieee']. This sets the figure width to fit a single column and ensures readability in black and white.
    • Nature: Use ['science', 'nature']. This configures the plot to use sans-serif fonts as recommended by Nature.