Formatting Plots for Paper in Python

Say you have a nice figure and you want to make it look good in your paper. Figures in  papers will be in the dimension of 8.9cm x 8.9cm (3.6in x 3.6in) so you want to make them clearly legible when shrunk to this size. Something like this.


You can set the size of your figure by doing

figure = matplotlib.pyplot.figure(figsize=(3.6, 3.6))

then you can check what it looks like in that dimension on your screen.

You may need to set the size of the plot so that all the axis titles are inside the figure. These parameters worked for me.

subplot = figure.add_subplot(1, 1, 1, position = [0.2, 0.15, 0.75, 0.75])

In the position bracket are [left (y axis position, x_0), bottom (x axis position, y_0), width (length of x axis), height (length of y axis)] of your plot.

To set the x and y limits on the axes, use set_xlim([xmin, xmax]) and set_ylim([ymin, ymax]).

To make the plot simple, you want to keep the variation of color and style to a minimum. Maybe combinations of a couple of colors and a couple of simple line styles. You can edit line width, line color, and line style by adding arguments to your plot command. 
Continue reading →

Sherpa – Week 1 (Plot)

This week, I began to play around with Sherpa, a scientific analysis tool written in Python. Sherpa has two options—you can either run it on its own (aka standalone Sherpa), or you can import it as a Python module, and utilize it in your own scripts. I want to use it for my own purposes, so I’m using it as a module. I’ve been taking notes to use for later documentation on how to use the software to make the spectroscopic measurements mentioned in my previous post.

This week, I learned how to take a spectrum (wavelength, flux, and statistical error arrays) and load them into a Sherpa data structure, and then how to plot the spectrum using Sherpa (instead of, say, matplotlib). For the purpose of brevity, I will hand wave these commands and jump to the plots.

Above is a Sherpa plot of one of the L dwarfs in my sample. It is high resolution NIRSPEC data, order 61 (to highlight the Potassium lines). In one easy command (specifically, plot_data), it plotted not only the spectrum, but the statistical error (which I supplied it). It also automatically labeled the axes, and added a title with the name of the target.

Above is a plot made in matplotlib. I made it not only to make a comparison of the plot styles of the two modules, but also to illustrate the difference between data taken on different nights. Each spectrum plotted here is order 61 from the same target as the Sherpa plot, but observed on different nights (the blue spectrum in this second plot exactly matches that of the first night). Also note that I did not plot the stat. error on the second figure. What stands out for me is that while you can easily notice the jumpiness of the pseudo-continuum, the pseudo-continuum itself is similar on each night. So I think this shows that making a model fit for measuring the potassium features will be roughly the same regardless of the night used.

-Dan