[Update 2012/04/22: Following suggestions from Jane Rigby (see comments below), I have created a couple of functions for changing properties of labels. These exists as separate code in the following Github Gist: https://gist.github.com/2326396 .]
Manually placing labels in a plot, especially if it is crowded, is cumbersome.
The Python module lineid_plot, has functions for automatically placing labels in a plot, in such a way that the labels do not overlap with each other. This is very useful, for example, in creating plots that have labels identifying features in a spectrum.
The code that adjusts the label positions is a direct translation of the appropriate section of the IDL code. Other features are implemented using the facilities provided by Matplotlib.
The module can be installed using pip or easy_install:
$ easy_install lineid_plot
$ pip install lineid_plot
The source code repository for the module is available on Github: http://github.com/phn/lineid_plot.
An example is show below. The plot can be customized in several ways, as shown in the documentation.
import numpy as np from matplotlib import pyplot as plt import lineid_plot wave = 1240 + np.arange(300) * 0.1 flux = np.random.normal(size=300) line_wave = [1242.80, 1260.42, 1264.74, 1265.00, 1265.2, 1265.3, 1265.35] line_label1 = ['N V', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II', 'Si II'] lineid_plot.plot_line_ids(wave, flux, line_wave, line_label1) plt.show()