dendrograms/dendro-core — pull request #29 by astrofrog (2013-06-20 12:17:31+00:00)
Title: Basic visualization utilities

This pull request implements basic visualization-related methods for Dendrogam. The first method is a sorting method that will sort the tree according to a key function, which by default is set to the peak flux of the substructure (including subtree). The other method is one that returns a list of lines, including a mapping from line objects to structures. With this in place, it's already possible to make simple plots:

```
import matplotlib.pyplot as plt
from astrodendro import Dendrogram
from astropy.io import fits

d = Dendrogram.compute(fits.getdata("MSX_E.fits"), verbose=True, min_data_value=1.e-4)

lines, mapping = d.get_lines()

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
for line in lines:
ax.add_line(line)
ax.set_xlim(0., 100.)
ax.set_ylim(0., 1.e-3)
fig.savefig('test.png')
```

![test](https://f.cloud.github.com/assets/314716/680951/11121886-d9a3-11e2-9a5d-4b1076d1530c.png)

```
d.sort(reverse=True) # by default, sort by peak value

lines, mapping = d.get_lines()

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
for line in lines:
ax.add_line(line)
ax.set_xlim(0., 100.)
ax.set_ylim(0., 1.e-3)
fig.savefig('test_sorted.png')
```

![test_sorted](https://f.cloud.github.com/assets/314716/680953/1eea1d0a-d9a3-11e2-904c-ffc4f11f864f.png)

The reason for returning the 'mapping' is that one can then set the picker attribute on the line objects to enable matplotlib object picking. Once this is done, we need the event handling function to access the structure for a given line. We might also need an inverse mapping since one may want to find e.g. all the lines belonging to the subtree of a structure. This would be easy too add.

Ultimately, we want ``Dendrogram`` to have a ``plot`` method, but I decided to start with these as a first step.

@ChrisBeaumont - what do you think of this so far?