[AstroPy] APLpy color bar for markers

Thøger Emil Rivera-Thorsen trive at astro.su.se
Mon Mar 7 12:55:20 EST 2016


Sorry for flooding, but I just worked out a better solution:

|import matplotlib.pyplot as plt import aplpy as ap f = plt.figure() fig 
= ap.FITSFigure('/path/to/myimage.fits', figure=f) a = fig.axes[0] # Or 
alternatively, a = plt.gca() x, y = fig.world2pixel(ra, dec) points = 
a.scatter(x, y, c=velocity, cmap='rainbow') f.colorbar(ax=a, 
use_gridspec=True) |

This should give you what you want, and look a good deal nicer than my 
first suggestion.
You can set the width etc. of the colorbar in the |f.colorbar()| call, 
just read the documentation (|f.colorbar?| in IPython).

On 03/07/2016 06:38 PM, Thøger Emil Rivera-Thorsen wrote:

> I would do this by tapping directly into the Matplotlib/pylab api to 
> do this:
>
> |import matplotlib.pyplot as plt import aplpy as ap fig = 
> ap.FITSFigure('myimage.fits') fig.show_grayscale() f, a = plt.gcf(), 
> plt.gca() x, y = fig.world2pixel(ra, dec) points = a.scatter(ra, dec, 
> c=velocity, cmap='rainbow') fig.colorbar(points) |
>
> The colorbar is not as neatly aligned as the APLPy function does, but 
> this can be refined and tweaked, if you read the matplotlib docs (or 
> you can just use it as-is).
>
> On 03/07/2016 04:52 PM, Ke Wang wrote:
>
>> Hi,
>>
>> This should be a simple question, but I just don't find an obvious 
>> solution:
>>
>> I use APLpy to plot a FITS image with nice wcs coordinates support, 
>> and overlay color coded markers:
>>
>> fig = aplpy.FITSFigure('image.fits')
>> fig.show_colorscale(cmap='gray')
>> fig.show_markers(ra, dec, c=velocity, cmap='rainbow')
>> fig.add_colorbar()
>>
>> This will plot a gray color bar (for the image). But I want to 
>> display the rainbow (for markers). Any idea would be appreciated.
>>
>> Cheers,
>> Ke
>>
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at scipy.org
>> https://mail.scipy.org/mailman/listinfo/astropy
>>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> https://mail.scipy.org/mailman/listinfo/astropy

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20160307/fff0a27e/attachment.html>


More information about the AstroPy mailing list