Feed on

Archive for the 'Python' Category


ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.get_xaxis().tick_bottom() ax.get_yaxis().tick_left()   Thanks StackOverflow!

To make long axis labels automatically wrap, use the textwrap module: import textwrap import pylab wrap_label_string = ‘\n’.join(textwrap.wrap(mylabel_string,30)) pl.ylabel(wrap_label_string,multialignment=’center’)

To adjust the relative ordering of plot items in matplotlib, use the “zorder” variable: pl.plot(x,y,zorder=1) # plots on bottom pl.plot(x,y,zorder=10) # plots on top

To hide the tick labels on the x-axis, but still preserve the ticks themselves (useful for grids): [label.set_visible(False) for label in ax.get_xticklabels()]



read csv files in python

Use CSV module and DictReader: taxa_fn = img_dn + “/00.taxon.tab.txt” taxa_d = {} with open(taxa_fn, ‘rb’) as taxa_f: csv_o = csv.DictReader(taxa_f, delimiter=’\t’) for line_d in csv_o: oid_n = line_d['taxon_oid'] name_s = line_d['taxon_display_name'] domain_s = line_d['domain'] status_s = line_d['seq_status'] taxa_d[oid_n] = {‘name’:name_s,’domain’:domain_s,’status’:status_s} #endfor #endwith

remove interpolation in imshow

matplotlib’s imshow interpolates between pixels by default. to produce non-interpolated output (more similar to matshow), use the following flag: interpolation=’nearest’

to change all font sizes on a matplotlib plot: matplotlib.rcParams.update({‘font.size’: 22}) (thanks stackoverflow!)

Next »

More blogs about http://desk.stinkpot.org:8080/tricks.