berkelem
berkelem

Reputation: 2115

Plotting non-standard axes

I am plotting an image using RA and Dec coordinates. The image overlaps the (RA, Dec) = (0,0) point. For the y-axis (Declination) this is fine, but for the x-axis, working in degrees, I am finding it difficult to plot this properly.

I want the plot to start at (RA, Dec) = (358, -2) and span four square degrees up to (2, 2). Is there a way to get python/matplotlib to understand that 360 degrees = 0 degrees on the x-axis?

This is how I started:

lowerleft_ra = 358.
lowerleft_dec = -2.
lx = lowerleft_ra
ly = lowerleft_dec
uy = lowerleft_dec + 4.
ux = lowerleft_ra + 4.

plt.imshow(image, origin = 'lower', extent = [lx, ux, ly, uy])

This makes the x-axis span from 358 to 362, which is not what I am looking for. I then tried modifying it as follows:

if lowerleft_ra + 4. > 360.:
    ux = lowerleft_ra + 4. - 360.
else:
    ux = lowerleft_ra + 4.

But this just sets the x-axis running in reverse order from 358 down to 2 deg.

How can I get it to go 358, 359, 0, 1, 2?

Upvotes: 1

Views: 269

Answers (1)

mfitzp
mfitzp

Reputation: 15545

The extents information passed to imshow is informing matplotlib about the size of the object you're plotting (scale, ratio, etc). Once you have plotted it you are free to adjust the axes manually. While I don't think you can tell matplotlib to plot an axis with non-linear values, you can replace the tick labels.

I suggest creating a scale that goes from -2 to +2 and then using the following method to apply the tick labels to your liking:

plt.xticks([-2,-1,0,1,2], [358,359,0,1,2])

Or using the API

ax.set_xticks([-2,-1,0,1,2])
ax.set_xticklabels([358,359,0,1,2])

This gives me the following plot:

enter image description here

Upvotes: 1

Related Questions