Skip to main content

Posts

Python Code in LaTeX

In A Student’s Guide to Python for Physical Modeling , we used the Listings package for LaTeX to format our code samples. In this post, we describe how we used the package and provide our style files for others to use. Typesetting Computer Code The listings package makes it easy to format code for typesetting in LaTeX. It allows the author to adjust virtually every aspect of how code is displayed. We used the package to develop our own syntax highlighting scheme. All code is displayed in a monospace (typewriter) font. Built-in functions and reserved words are bold and green. Python exceptions are bold and red. Modules and functions from NumPy and PyPlot are bold and black. Modules and functions from other modules are bold and blue. Strings are red. Keyword arguments to functions are italic. Comments are blue italic. This scheme is similar to the one used in Spyder. It allows a reader to distinguish built-in functions and modules from variable names and user-defined functi...

Making Plots for Publication

Overview This document extends the discussion of plots and graphs given in A Student’s Guide to Python for Physical Modeling . Here we give some recipes that work on our installation. If they don’t work on yours, please comment on that, especially if you find a workaround. This post describes the following: Setting figure size Importing the SGPniceGraphics module Functions and parameters defined in the module Fixing crowded graphs Saving graphs for modification in other art software Typesetting labels with LaTeX Other rc settings CMYK color Exporting raster images Setting Figure Size You can create a figure window of a specific size before plotting with the command myfigsize = (6, 3) plt.figure(frameon=False, figsize=myfigsize) The first keyword argument suppresses the colored panel in the back of the figure, so you won’t need to delete it by hand in some drawing software. The second keyword argument specifies the desired width and height of t...