[AstroPy] equivalent routine to IDL Astronomy Library lineid_plot

Prasanth oneaufs at gmail.com
Sat Sep 17 01:46:23 EDT 2011


Hello,

Thanks for trying it out.

I can't reproduce the error you are getting while running from the command
line. I tried it in Ubuntu 11.04 using Python 2.6 with Matplotlib 0.99.3 and
1.0.1, and Python 2.7 with Matplotlib 1.0.1.

I could re-create the exception by using the following code, though:

>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> # No error here.
>>> lineid_plot.plot_line_ids(wave, flux, line_wave, line_label1, ax=ax)
(<matplotlib.figure.Figure at 0xb387dec>,
 <matplotlib.axes.AxesSubplot at 0xb38386c>)
>>> plt.clf()

>>> # Try using the Axes that was cleared by plt.clf(). Raises exception.
>>> lineid_plot.plot_line_ids(wave, flux, line_wave, line_label1, ax=ax)

But if I don't pass the Axes that was cleared up by plt.clf(), then I don't
run into any problem.

>>> lineid_plot.plot_line_ids(wave, flux, line_wave, line_label1)

I was going to remove the arrow head, over the next few commits.

In any case, the function plot_line_ids() returns both the Figure and the
Axes. So one can easily customize the Annotation boxes and arrows by looking
through the ax.texts list. One thing I want to do is to assign meaningful
unique labels to the label attribute of these boxes. They can then be easily
found and customized, say using fig.findobj().

Thanks,
Prasanth
On Fri, Sep 16, 2011 at 11:03 PM, Jonathan Slavin
<jslavin at cfa.harvard.edu>wrote:

> 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 at 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 at 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 at scipy.org
> >         http://mail.scipy.org/mailman/listinfo/astropy
> >
> >
> --
> ______________________________________________________________
> Jonathan D. Slavin              Harvard-Smithsonian CfA
> jslavin at cfa.harvard.edu         60 Garden Street, MS 83
> phone: (617) 496-7981           Cambridge, MA 02138-1516
>  cell: (781) 363-0035           USA
> ______________________________________________________________
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20110917/a3f91cfc/attachment.html>


More information about the AstroPy mailing list