import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import pandas as pd
%matplotlib inline
pSiteFile = 'pSite_growth.csv'
#PhosphoSite/PhosphoSitePlus human tyrosine phosphorylation sites
df = pd.DataFrame.from_csv(pSiteFile)
/anaconda3/lib/python2.7/site-packages/ipykernel_launcher.py:10: FutureWarning: from_csv is deprecated. Please use read_csv(...) instead. Note that some of the default arguments are different, so please refer to the documentation for from_csv when changing your function calls # Remove the CWD from sys.path while we load stuff.
nrows = 3
ncols = 2
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)
fig.tight_layout()
fig.autofmt_xdate()
idxCol = 0
idxRow = 0
#keys = ('Phosphoserine', 'Phosphothreonine', 'Phosphotyrosine','N6-acetyllysine', 'Ubiquitination', 'Sumoylation')
for key in keys:
keySubset = df[df['Modification']==key]
axes[idxRow, idxCol].bar(keySubset['Year'], keySubset['Number'])
axes[idxRow,idxCol].set_title(key)
#axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_useOffset(False)
axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_scientific(False)
# Tell matplotlib to interpret the x-axis values as dates
#axes[idxRow,idxCol].xaxis_date()
idxCol = idxCol + 1
if idxCol % (nrows-1) == 0:
idxCol = 0
idxRow += 1
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-3-ea6b652b473d> in <module>() 10 for key in keys: 11 keySubset = df[df['Modification']==key] ---> 12 axes[idxRow, idxCol].bar(keySubset['Year'], keySubset['Number']) 13 axes[idxRow,idxCol].set_title(key) 14 #axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_useOffset(False) IndexError: index 3 is out of bounds for axis 0 with size 3
nrows = 1
ncols = 1
fig, axes = plt.subplots(nrows=nrows, ncols=ncols)
fig.tight_layout()
fig.autofmt_xdate()
idxCol = 0
idxRow = 0
#keys = ('Phosphoserine', 'Phosphothreonine', 'Phosphotyrosine','N6-acetyllysine', 'Ubiquitination', 'Sumoylation')
keys = ['Phosphotyrosine']
for key in keys:
keySubset = df[df['Modification']==key]
axes[idxRow, idxCol].bar(keySubset['Year'], keySubset['Number'])
axes[idxRow,idxCol].set_title(key)
#axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_useOffset(False)
axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_scientific(False)
# Tell matplotlib to interpret the x-axis values as dates
#axes[idxRow,idxCol].xaxis_date()
idxCol = idxCol + 1
if idxCol % (nrows-1) == 0:
idxCol = 0
idxRow += 1
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-11-855aeb80bd14> in <module>() 10 for key in keys: 11 keySubset = df[df['Modification']==key] ---> 12 axes[idxRow, idxCol].bar(keySubset['Year'], keySubset['Number']) 13 axes[idxRow,idxCol].set_title(key) 14 #axes[idxRow,idxCol].get_xaxis().get_major_formatter().set_useOffset(False) TypeError: 'AxesSubplot' object has no attribute '__getitem__'
keySubset = keySubset.sort_values('Year')
keySubset = keySubset[keySubset.Year !=2018]
f = keySubset.plot.bar(x='Year', y='Number', legend=False, rot=45, fontsize=12)
fig = f.get_figure()
fig.savefig('pTyr_growth_to2017.eps')