Python FAQs

On this page, we have compiled a list of questions about Python programming that come up frequently in our work. We hope they'll be a useful resource for anybody interested in using Python to plot and interpret data, run simulations, and process text.

Plots and Figures

How do I plot data in Python?

How do I change the default font size in Matplotlib figure?

How do I make subplots in Python / Matplotlib?

How do I change the line or marker style in a Matplotlib plot?

How do I fix crowded axes in a Python/Matplotlib plot?

How do I export a matplotlib figure?

How do I change the line or marker color in a Matplotlib plot?

How do I change the line width (thickness) of a Matplotlib curve?

How do I add custom annotations to a matplotlib figure?

How do I control data limits in Matplotlib figures?

How do I add a legend to a matplotlib figure?

How do I control the location of a matplotlib legend?

How do I add axis labels to a Matplotlib figure?

How do I control the location of matplotlib axes?

How do I make tick marks display inside a matplotlib axis?

How do I make filled curves in Matplotlib plots ?

How do I make a transparent fill in Matplotlib?

How do I change the background / foreground order of Matplotlib curves ?

How do I make a waterfall plot in Python / Matplotlib?

How do I use colormaps to color curves in Matplotlib?

How do I set the aspect ratio of Matplotlib axes?

How do I import data between two begin/end markers in a text file?

Matrices and Vectors

How do I create and manipulate matrices in Python?

How do I make NumPy matrix printouts easier to read?

How does NumPy array indexing work?

How do I calculate a matrix product in Python?

How do I calculate a matrix inverse in Python?

How do I calculate eigenvalues and eigenvectors in Python?

How do I print NumPy arrays to a text file?

How do I control output precision with np.savetxt()?

How do I load tab delimited data from a text file into a NumPy array?

How do I load comma delimited data from a text file into a NumPy array?

Spectroscopy and Signal Processing

How do I load a spectrum into Python from a text file?

How do I interpolate spectroscopic data to a new frequency axis?

How do I baseline correct a spectrum?

How do I smooth a spectrum?

How do I use Python to fit a curve or spectrum?

How do I correct for atmospheric water vapor in FTIR spectra?

What is "reabsorption"?

How do you recognize artifacts in an experimental UV/Vis or IR spectrum?