leejjoon / pywcsgrid2

astromonical fits image for python matplotlib
http://leejjoon.github.com/pywcsgrid2/
MIT License
25 stars 13 forks source link

Axes Plotting Issue #9

Closed EDrabek closed 12 years ago

EDrabek commented 12 years ago

Hi,

I am having an issue when attempting to plot a position-velocity diagram (x-axis position using an offset axis I created in arc min and y-axis in velocity). The program runs smoothly and outputs a plot, but the axes are wrong. I believe the x-axis is centred correctly at CPIX1 but the labels seem to be in pixels and I'm unsure about the y-axis. Here is the snippet of the program I am using:

def pv_plot(pvhdulist,plotname): pvplotdata=numpy.where(pvhdulist[0].data>=0,numpy.sqrt(pvhdulist[0].data),0) fig=plt.figure() ax=pywcsgrid2.axes_wcs.AxesWcs(fig,[0.2,0.2,0.7,0.7],header=pvhdulist[0].header) ax.set_ticklabel1_type("absval",nbins=5) ax.set_ticklabel2_type("absval",scale=0.001,nbins=9) pylab.imshow(pvplotdata, origin="low", interpolation="nearest", aspect=0.04, vmin=0, vmax=10,cmap=pylab.cm.gist_heat) plt.savefig(plotname+".png",dpi=300,orientation="landscape",transparent="True",bbox_inches="tight")

No matter how I change with ax.set_ticklabel1_type (if I change it to "arcmin" and choose an offset for example for the x-axis), the axes ticks do not change.

Has this problem been encountered before?

leejjoon commented 12 years ago

My guess is that you're creating an axes but not adding it to a figure. So, imshow creates its own.

See if adding this line helps. This needs to be added after you create an axes with AxesWcs.

fig.add_axes(ax)

If this does not help, please post an simple but complete code.

EDrabek commented 12 years ago

I included your suggestion and received the following error:

Traceback (most recent call last): File "run_PV_outflow.py", line 21, in PV_outflow.pv_plot(pv_input,test_pv_output) File "/Users/emily/PV_outflow.py", line 70, in pv_plot fig.add_axes(ax) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 683, in add_axes key = self._make_key(_args, _kwargs) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 630, in _make_key key = fixlist(args), fixitems(kwargs.items()) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 626, in fixlist if iterable(a): a = tuple(a) File "/Library/Python/2.7/site-packages/pywcsgrid2/axes_wcs.py", line 1270, in getitem key = proj.sub([1,2]) File "/Library/Python/2.7/site-packages/pywcsgrid2/wcs_helper.py", line 240, in sub return self.substitute(axis_nums_to_keep, [0] \ self.naxis) File "/Library/Python/2.7/site-packages/pywcsgrid2/wcs_helper.py", line 264, in _get_naxis return self._pywcs.wcs.naxis AttributeError: 'int' object has no attribute 'wcs'

leejjoon commented 12 years ago

Okay, this is something that has been fixed in the master branch. I just pushed new release (v0.1b2) that I believe fixes this bug. Please try it (you should be able to download it from the download page) and see if it works.

EDrabek commented 12 years ago

It seems to have been fixed! Thank you for your quick response. Cheers.