Tickmarks in matplotlib

Over time I’ve become more and more a lover of Python. I still don’t use half of the fancy stuff and very much use it as a scripting language, but as you can see from some previous posts I really do think that it is well suited for astronomical purposes. Anyway, I digress, one thing that was bugging me was producing publication quality plots. I’ve still got things to tweak with my plots but I think I’m finally happy with my script and thought I’d share one vital thing – tickmark lenghts. It took me ages to figure out what paramter this was called and lets be honest if no body else gets any use from this I’m bound to the next time I forget / can’t find any code with this implmeneted in. So here we go, how change tickmark lengths in matplotlib:

import string, sys, math, scipy, numpy, pylab
from pylab import *
#DATA
x = [0,1,2,3,4]; y = [2,3,4,5,6]
#Plotting
fig = plt.figure(figsize=(9, 8))
fig.subplots_adjust(left=None, bottom=0.2, right=None, top=0.97,wspace=None, hsp
ace=None)
ax1 = fig.add_subplot(111)
ax1.semilogx(x,y)
setp(gca().get_ymajorticklabels(), fontsize=’large’)
setp(gca().get_xmajorticklabels(), fontsize=’large’)
labels = setp(gca(), ylabel=’y axis’, xlabel=’x axis’)
setp(labels, fontsize=’large’)
for l in ax1.get_xticklines() + ax1.get_yticklines():
l.set_markersize(6)
l.set_markeredgewidth(1.2)
for l in ax1.yaxis.get_minorticklines()+ax1.xaxis.get_minorticklines():
l.set_markersize(3)
l.set_markeredgewidth(1.2)
save = “test.eps”
pylab.savefig(save)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: