Plotting with Matplotlib

See here for some examples. The codes here show how to set plot parameters in one place and use it in other scripts.

Matplotlib settings

from matplotlib import rcParams
rcParams['font.size'] = 12
rcParams[''] = 'serif'
rcParams['figure.autolayout'] = True
rcParams['lines.linewidth'] = 2
rcParams['lines.markersize'] = 2
rcParams['axes.titlesize'] = 12
rcParams['axes.labelsize'] = 12
rcParams['text.usetex'] = True    # This will use Latex fonts (slow)

Line width and marker size

lw = 3 # linewidth
ms = 8 # marker size

Tight axis

To make both axes tight


Make x axis tight

plt.autoscale(enable=True, axis='x', tight=True)

Set axes range

To set both axes

plt.axis([0, 1, -1, 1])

To set independently


Plotting backend

Plotting backends might create problems on mac. If this happens, then try this

import matplotlib
import matplotlib.pyplot as plt

NOTE: You must set the backend before importing pyplot.

You can set this as default; for example in anaconda, I create a file

and in this put the following
import matplotlib