hide tick lines in matplotlib
Posted in Python on February 1st, 2012 No Comments »
to hide the tick lines in matplotlib: xaxis = ax.xaxis xaxis.set_ticks_position(‘none’)
Posted in Python on February 1st, 2012 No Comments »
to hide the tick lines in matplotlib: xaxis = ax.xaxis xaxis.set_ticks_position(‘none’)
Posted in Python on February 1st, 2012 No Comments »
to create only horizontal grid lines in matplotlib: fig, ax = pylab.subplots(1) ax.xaxis.grid(True) pylab.grid()
Posted in Python on January 31st, 2012 No Comments »
let’s say you’ve made a bar plot and you want to label the bars by strings (e.g. ‘A’, ‘B’) instead of the default number range. to do with a list of labels named ‘bar_l’: import pylab as pl pl.xticks(np.arange(len(bar_l)),bar_l,rotation=45)
Posted in Python on September 28th, 2011 No Comments »
to change the default line color order (color cycle in matplotlib-speak): ax.set_color_cycle(['green', 'orange', 'blue', 'red','brown','pink']) note that this will also go ahead and reset the line counter.
Posted in Python on September 20th, 2011 No Comments »
nan’s cause problems with the fill_between plots in matplotlib. to fix, use the “where” input argument: fig, ax = pl.subplots(1) ax.fill_between(x_v,0,y_v,where=np.isfinite(y_v))
Posted in Python on August 31st, 2011 No Comments »
to only show the bottom ticks in a matplotlib figure: axis_x = ax.xaxis axis_x.tick_bottom()
Posted in Python on August 8th, 2011 No Comments »
use the itertools and random modules in python to get N pairwise combinations of a list’s items: combo_it = itertools.combinations(my_list,2) combo_l = list(combo_it) random.shuffle(combo_l) pair_l = combo_l[:N]
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 No Comments »
to move your x-axis label to the top of the figure: ax.xaxis.set_label_position(‘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)