Praveen Chandrashekar

Centre for Applicable Mathematics, TIFR, Bangalore

[ People | News | Codes | Talks | Teaching | Publications | Calendar | Hiking | Contact ]

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'] = 14
rcParams[''] = 'serif'
rcParams['figure.autolayout'] = True
rcParams['lines.linewidth'] = 2
rcParams['lines.markersize'] = 6
rcParams['axes.titlesize'] = 14
rcParams['axes.labelsize'] = 14
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