leejjoon / pywcsgrid2

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

White tick marks #5

Closed ghost closed 13 years ago

ghost commented 13 years ago

Hi. I have a question. I would like to have white tick marks, but I am not happy with the default format. I have a simple script to reproduce this issue.

import numpy, pyfits, pywcsgrid2, pylab
values = [
        ["NAXIS",  2,          ],
        ["NAXIS1", 5,          ],
        ["NAXIS2", 5,          ],
        ["CTYPE1", 'GLON-ZEA'  ],
        ["CRPIX1", -12.5,      ],
        ["CRVAL1", 0,          ],
        ["CDELT1", -0.1,       ],
        ["CTYPE2", 'GLAT-ZEA', ],
        ["CRPIX2", 12.5,       ],
        ["CRVAL2", 0,          ],
        ["CDELT2", 0.1,        ],
]
cards = [ pyfits.Card(*i) for i in values]

header=pyfits.Header(cards=cards)

ax=pywcsgrid2.subplot(111, header=header)

ax.imshow(numpy.ones((25,25)), origin='lower')

ax.axis[:].set_zorder(100) # I am not sure if htis is needed?
ax.tick_params(colors='white') 

pylab.savefig('plot.pdf')

When I run it, the ticks are white, but they are half on top of and half below the axes. Is there an easy way to make the white ticks completely under (or over) the axes?

leejjoon commented 13 years ago

In the current implementation, the tick marks are always on top of axis lines. They seem half on top of and half below as the axis line is drawn with a finite width while the tick marks are drawn from the axis line without accounting the finite line width. Unfortunately, the order of drawing for axis line and tick marks are hardcoded. So, it is not straightforward to modify this behavior as a user. You may monkey-patch the axis_artist module.


    def draw(self, renderer):
        'Draw the axis lines, tick lines and labels'

        if not self.get_visible(): return

        renderer.open_group(__name__)

        self._axis_artist_helper.update_lim(self.axes)

        dpi_cor = renderer.points_to_pixels(1.)
        self.dpi_transform.clear().scale(dpi_cor, dpi_cor)

        self._draw_ticks(renderer)

        self._draw_line(renderer)

        self._draw_label(renderer)

        renderer.close_group(__name__)

    import mpl_toolkits.axisartist .axis_artist
    mpl_toolkits.axisartist .axis_artist.AxisArtist.draw = draw

    # your code comes here.

Include above code snippet in your code and the tick marks will be under your axis lines.

I guess it is better if one can customize this behavior (I think the default behavior should be that tick marks are under axis lines). I'll try to fix this soon.

-JJ

ghost commented 13 years ago

Thank you for you quick reply JJ.

Its certianly not hugely important so don't loose any sleep over this.

But I think most people would agree that by default tick marks should come under the axis lines. So this would be a very welcome addition to the code =)