[AstroPy] equivalent routine to IDL Astronomy Library lineid_plot

Jonathan Slavin jslavin@cfa.harvard....
Fri Sep 16 12:33:37 CDT 2011


Hi Prasanth,

Nice work!  The images of plots look good.  Unfortunately I'm running
into a problem when running the example:

/export/slavin/python/phn-lineid_plot-a88d5f0/lineid_plot.py in
plot_line_ids(wave, flux, line_wave, line_label1, label1_size, extend,
**kwargs)
    182     # coordinates and extract the width.

    183     for box in ax.texts:
--> 184         b_ext = box.get_window_extent()
    185         box_widths.append(b_ext.transformed(ax_inv_trans).width)
    186 

/usr/local/lib/python2.6/site-packages/matplotlib/text.pyc in
get_window_extent(self, renderer, dpi)
    736             self._renderer = renderer
    737         if self._renderer is None:
--> 738             raise RuntimeError('Cannot get window extent w/o
renderer')
    739 
    740         bbox, info = self._get_layout(self._renderer)

RuntimeError: Cannot get window extent w/o renderer

I haven't been able to get it to work from the command line -- i.e. the
__name__ = "__main__", doing python lineid_plot -- though I have gotten
it to work in an interactive session.  I think an Axes instance is
necessary, so you might want to add ax=None as an explicit keyword and
add:
if ax == None:
    ax = plt.gca()

For my part, I'd prefer not to have arrow heads on the lines, so I would
change the arrowstyle in arrowprops to "-".  I'll look over the code
some more and may offer more suggestions.

Thanks,
Jon

On Fri, 2011-09-16 at 20:32 +0530, Prasanth wrote:
> Hello,
> 
> My attempt at implementing the lineid_plot.pro algorithm is available
> at 
> http://github.com/phn/lineid_plot. 
> 
> The automatic layout calculation is identical to that in the IDL
> procedure. But I 
> have tried to make use of the annotate feature provided by Matplotlib
> for the rest of the
> code.
> 
> I don't have access to IDL and hence couldn't properly explore the
> working of
> the IDL code. GDL can't run the code.
> 
> After implementing the layout calculations, the rest of the code,
> surprisingly, turns out 
> to be not difficult to write at all. This probably means that I am
> blind to some 
> obvious problems!
> 
> Feedback will be greatly appreciated.
> 
> Thanks,
> Prasanth
> 
> On Wed, Aug 24, 2011 at 8:49 PM, Jonathan Slavin
> <jslavin@cfa.harvard.edu> wrote:
>         If I had the time to do that adaptation, I'd certainly do it
>         -- and may
>         yet -- but it does depend on a lot of things that are very IDL
>         specific
>         such as the character size and plot region, etc.  I think that
>         there are
>         some good hints in the discussion on automatically creating
>         enough room
>         for tick labels
>         (http://matplotlib.sourceforge.net/faq/howto_faq.html),
>         but there's quite a bit more needed than that.
>         
>         Jon
>         
>         On Wed, 2011-08-24 at 11:48 -0300, Taro Sato wrote:
>         > I have my own custom routine to display line identifications
>         at given
>         > redshift but it's not smart enough to avoid overlapping; it
>         only
>         > alternates the offsets so that adjacent labels won't always
>         overlap.
>         > What you have in your example plot is certainly doable with
>         MPL...
>         > It's tricky to ensure that labels are readable most of the
>         time but
>         > since you know how to approach the problem, why don't you
>         create one
>         > and make it available publicly!  If the desired algorithm
>         needed is
>         > already coded in the IDL script it shouldn't be too
>         painful.  :D
>         --
>         
>         ______________________________________________________________
>         Jonathan D. Slavin              Harvard-Smithsonian CfA
>         jslavin@cfa.harvard.edu         60 Garden Street, MS 83
>         phone: (617) 496-7981           Cambridge, MA 02138-1516
>          cell: (781) 363-0035           USA
>         ______________________________________________________________
>         
>         
>         
>         _______________________________________________
>         AstroPy mailing list
>         AstroPy@scipy.org
>         http://mail.scipy.org/mailman/listinfo/astropy
>         
> 
-- 
______________________________________________________________
Jonathan D. Slavin              Harvard-Smithsonian CfA
jslavin@cfa.harvard.edu         60 Garden Street, MS 83
phone: (617) 496-7981           Cambridge, MA 02138-1516
 cell: (781) 363-0035           USA
______________________________________________________________



More information about the AstroPy mailing list