tueplots

repository·main·Indexed 20 days ago

https://github.com/pnkraemer/tueplots

A matplotlib extension for creating publication-ready scientific plots. It helps researchers manage figure dimensions and font sizes to match specific venue requirements (e.g., ICML, NeurIPS) without imposing strict aesthetic opinions. The library provides a stateless design for compatibility, along with predefined RGB color constants, palettes, and specialized marker styles via the tueplots.constants and tueplots.markers modules.

Tokens
10.9K
Snippets
38
Records
60
Agent score
72%

What's inside tueplots

  1. What is TUEplots

    main
    TUEplots is a lightweight extension for matplotlib designed to adapt figure sizes and configurations for scientific publications. It works by producing configurations compatible with matplotlib's rcParams, providing pre-configured bundles for fonts, figure sizes, font sizes, and color schemes tailored to specific academic venues.
  2. Overview of TUEplots

    main

    TUEplots is an extension for matplotlib designed to facilitate the creation of scientific plots for publications (papers, presentations, posters).

    Unlike many styling libraries, TUEplots focuses on avoiding common publication issues such as:

    • Incorrect figure sizes (e.g., not matching publication text-width).
    • Inappropriate font sizes.
    • Inconsistencies across different figures.

    It is designed to be non-opinionated regarding aesthetics (colors, markers, etc.) and follows a stateless design to ensure compatibility with other matplotlib extensions.

  3. Access color constants in tueplots.constants.color

    main

    The tueplots.constants.color package provides access to predefined color palettes and RGB color definitions used for scientific plotting. This package is organized into two main submodules:

    • tueplots.constants.color.palettes: Contains various color palettes suitable for scientific publications.
    • tueplots.constants.color.rgb: Contains specific RGB color definitions.

    You can use these constants to ensure consistent and publication-quality coloring across your matplotlib plots.

  4. How TUEplots manages state and compatibility

    main

    TUEplots operates without internal state. It works by generating and passing around dictionaries containing key-value pairs that match standard matplotlib parameters (rcParams).

    Because it does not modify global state directly, you can manage settings using standard matplotlib patterns:

    1. Global changes: Use matplotlib.pyplot.rcParams.update() to apply settings across your entire session.
    2. Context-specific changes: Use matplotlib.pyplot.rc_context() to apply settings only to a specific block of code.

    This approach ensures that TUEplots remains compatible with other matplotlib-based tools and extensions.

  5. Access constants in the tueplots.constants package

    main

    The tueplots.constants package provides centralized access to predefined constants used for scientific plotting, specifically focusing on markers and colors. This ensures consistency across different plots in a publication. The package is organized into submodules:

    • tueplots.constants.markers: Contains predefined marker styles.
    • tueplots.constants.color: Contains predefined color palettes and color constants.
  6. Apply tueplots configurations to matplotlib

    main

    Most functions in tueplots (such as markers) return dictionaries that follow the matplotlib rcParams format. You can apply these configurations in two ways:

    1. As a context manager: Use plt.rc_context() to apply settings only to a specific block of code. This is recommended to avoid polluting global state.
    2. Globally: Use plt.rcParams.update() to change the configuration for the entire session.
    import matplotlib.pyplot as plt
    from tueplots import markers
    
    # Get the configuration dictionary
    config = markers.inverted()
    
    # Option 1: Use as a context manager (local scope)
    with plt.rc_context(config):
        plt.plot([1, 2, 3], marker='o')
        plt.show()
    
    # Option 2: Update global configuration (global scope)
    plt.rcParams.update(config)
  7. Customize ICML 2022 figures with figsizes, fontsizes, and fonts

    main

    If you prefer not to use a complete bundle, you can manually configure specific aspects of the ICML 2022 style using individual modules:

    • Figure Sizes: Use figsizes.icml2022_full() for full-width figures or figsizes.icml2022_half(nrows=2, ...) for half-width figures.
    • Font Sizes: Use fontsizes.icml2022() to set standard sizes for labels, legends, and ticks.
    • Font Families: Use fonts.icml2022() for standard serif/sans-serif settings, or fonts.icml2022_tex(family="sans-serif") to enable LaTeX-based font configurations.
    from tueplots import figsizes, fontsizes, fonts
    
    # Configure figure size
    plt.rcParams.update(figsizes.icml2022_full())
    
    # Configure font sizes
    plt.rcParams.update(fontsizes.icml2022())
    
    # Configure font families
    plt.rcParams.update(fonts.icml2022(family="serif"))
  8. Determine the scope of contributions

    main

    Contributions to tueplots should focus on the style files used in scientific papers. This includes:

    • New versions of existing styles: e.g., adding icml2025 if icml2023 already exists.
    • New venues: Adding style files for conferences or journals not currently supported (e.g., CVPR).

    For any other type of contribution, you should create an issue first to discuss it with the maintainers.

  9. Identify correct font and figure settings from LaTeX templates

    main

    When implementing a new style, use the conference/journal's author instructions to find figure sizes and font sizes.

    Important Guidelines:

    • Font Size: Use the Figure captions as your reference for font size, not the main body text.
    • Font Selection: Consult the LaTeX style file source code to identify the correct font implementation. Common patterns include:
      • If \includepackage{times} is used: Use the same configuration as ICLR-2023.
      • If \includepackage{ptm} is used: Mirror this by including the same package (even if it is obsolete) to match the template closely.
      • If no font-related package is included: It likely uses Computer Modern. Copy the configuration from JMLR-2001.

    Note: Be skeptical of templates claiming to use 'Times New Roman' without a LaTeX style file, as native Times New Roman implementation in LaTeX typically requires XeLaTeX.