[AstroPy] how to make a sky plot
Eric Jensen
ejensen1 at swarthmore.edu
Wed Apr 2 10:31:44 EDT 2014
On Apr 2, 2014, at 10:10 AM, Jonathan T. Niehof wrote:
> (Don't know if it's possible to label RA in hours
> instead of degrees longitude.)
If it isn't possible to do this directly in the plotting routine, you could do something like this to manipulate the x-axis tick labels directly. (But if you do this, don't forget when looking at your plot and modifying your plot code that you are really still plotting a variable in degrees even if your label is in hours! e.g. your limits would still have to be degrees )
fig = plt.figure()
ax = fig.add_subplot(111)
[ Code in here to plot your data and set axis limits. ]
# Need to draw the canvas in order for ticklabels to be set:
fig.canvas.draw()
ticklist= ax.get_xticklabels()
new_label_list = []
for label in ticklist:
# Get rid of dollar signs if using Latex labels:
string= label.get_text().replace('$', '')
# Some labels may be blank, leave as-is:
if string == '':
new_label = string
else:
# Get numeric equivalent, change to hours:
tick_num = float(string)
tick_num = tick_num/15.
# Note that this rounds to integer, might not be what you want:
tick_string = "%d" % tick_num
# Add a raised "h" to denote hours:
new_label = "$" + tick_string + "^h$"
new_label_list.append(new_label)
new = ax.set_xticklabels(new_label_list)
(Based on code from http://stackoverflow.com/questions/11244514/matplotlib-modify-tick-label-text )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20140402/7f83acc3/attachment.html>
More information about the AstroPy
mailing list