Posted in Python, R on August 3rd, 2011 No Comments »
Importing arrays from numpy to rpy2 can throw the following error: ValueError: Nothing can be done for the type <type ‘numpy.ndarray’> at the moment. To resolve, add the following to the top of your Python code: import rpy2.robjects.numpy2ri rpy2.robjects.numpy2ri.activate()
Posted in Python on July 15th, 2011 2 Comments »
to move your x-axis label to the top of the figure: ax.xaxis.tick_top()
Posted in Python on July 8th, 2011 No Comments »
to set the size of a figure in matplotlib (in inches): fig.set_size_inches(8,4)
Posted in Python on July 6th, 2011 No Comments »
to give NaNs their own specific color in a plot, use a masked array. for example, the code below will color NaNs white: import numpy.ma import pylab as pl masked_X = numpy.ma.array(X,mask=np.isnan(X)) cmap.set_bad(‘w’,1.) fig, ax = pl.subplots(1) im1 = ax.matshow(masked_X)
Posted in Python on July 6th, 2011 No Comments »
to define the color range used by matshow, use the vmin and vmax arguments: import pylab as pl fig, ax = pl.subplots(1) im1 = ax.matshow(X,vmin=0,vmax=1)
Posted in Python on July 6th, 2011 No Comments »
to set the range of the x or y axis in a matplotlib figure: import pylab as pl pl.xlim([day_min,day_max]) pl.ylim([day_min,day_max])
Posted in Python on July 2nd, 2011 1 Comment »
to remove the ytick labels in matplotlib: pylab.setp([a.get_yticklabels() for a in fig.axes],visible=False)
Posted in Python on July 2nd, 2011 No Comments »
to hide the yticks in matplotlib: pylab.setp([a.get_yticklines() for a in fig.axes],visible=False)
Posted in Python on June 27th, 2011 No Comments »
to subtract days from a datetime object in python: from datetime import date, timedelta d=date.today()-timedelta(days=days_to_subtract) thanks steve b.!
Posted in Python on June 27th, 2011 3 Comments »
to change the font size in a matplotlib legend: import pylab import matplotlib.font_manager as fm fig = pylab.figure() prop = fm.FontProperties(size=5) figlegend.legend(handle_l,label_l,prop=prop)