Getting Ready
Import packages
from numpy.random import randn
import matplotlib.pyplot as plt
from pandas import Series, DataFrame,date_range
from matplotlib import cm
Read in data
dat=pd.read_csv("C:\\Users\duan\Desktop\PythonDataProcessingVisualization\metaDataMean.txt", sep='\s+')
Line Plot
plt.figure()
dat.samplemeans.plot()
plt.figure()
dat.samplemeans.plot(secondary_y=True, style='g')
For list of named colors see here
Change plotting style and add legend
plt.figure();dat.samplemeans.plot(style='k--', label='sample means'); plt.legend()
Bar Plot
plt.figure();
dat.samplemeans.plot(kind='bar')
add a horizontal line
plt.figure();
dat.samplemeans.plot(kind='bar'); plt.axhline(10,linewidth=4, color='r')
plot horizontal bars
plt.figure();
dat.samplemeans.plot(kind='barh',color="pink")
plt.figure();
dat.samplemeans.plot(kind='barh',color = [cm.rainbow(i) for i in np.linspace(0, 1, len(dat.samplemeans))])
Histogram Plot
plt.figure();
dat.samplemeans.hist()
Box Plot
plt.figure();
bp = dat.boxplot()
Define a title
plt.figure();
bp=dat.boxplot()
bp.set_title('My box plot')
Boxplot by celltype
plt.figure();
bp = dat.boxplot(by='genotype')
Better layout by excluding the automatic title
plt.figure();
bp = dat.boxplot(by='genotype')
plt.suptitle('') # that's what you're after
plt.show()
More sophisticated plotting can better reveal the trend
plt.figure();
bp = dat.boxplot(column=['samplemeans'], by=['celltype','genotype'])
title_boxplot = 'expression means'
plt.title( title_boxplot )
plt.suptitle('')
plt.show()