Skip to content

How-to Guides

Format a matplotlib figure

Final result:

Matplotlib figure example

Steps:

  1. Install the STIX fonts.
  2. Import the uqtils.default style template:

    import matplotlib.pyplot as plt
    
    plt.style.use('uqtils.default')  # Globally in the file, or...
    
    with plt.style.context('uqtils.default'):
        plt.plot(...)
    
  3. Use the ax_default convenience method for adding a legend and axis labels:

    fig, ax = plt.subplots()
    h1, = ax.plot(x, y, '-r')
    ...
    leg = {'handles': [h1, ...], 'labels': [..., 'Model', 'Experiment']}
    
    uqtils.ax_default(ax, 'Axial distance from anode (mm)', 'Axial ion velocity (km/s)',
                      legend=leg)
    
  4. Optionally adjust other plot settings:

    with matplotlib.rc_context({'font.size': 14}):
        plt.plot(...)