Ich möchte einen grouped barplot erzeugen.
Als erstes lese ich alle tab Dateien ein (Bsp tab file), dann soll es mir 2 Spalten von aus den Dateien für die x-Achse auslesen('special name' and 'ab') . In 'special name' sind 3 verschiedene namen (Tm, ui, ac), und jedem dieser namen sind 4-7 'ab'-Namen zugewiesen.
also soll es 3 hauptabschnitte geben mit jeweils 4-7 weiteren balken.
Code: Alles auswählen
#Beispiel tab file
Names names_id first second special_name ab
lili 1 a b Tm a
Katrin 2 c d Tm u
Paul 3 e f ui f
bob 4 g h ui b
tina 5 i j ac a
Code: Alles auswählen
%matplotlib inline
import matplotlib as mpl
from matplotlib.gridspec import GridSpec
import matplotlib.pyplot as plt
import sys
import os
import glob
import seaborn as sns
import pandas as pd
import ggplot
from ggplot import aes
sns.set(style= "whitegrid", palette="pastel", color_codes=True )
tab_folder = 'myData'
out_folder ='myData/plots'
tab = glob.glob('%s/R*.tab'%(tab_folder))
#is reading all my data
for i, tab_file in enumerate(tab):
folder,file_name=os.path.split(tab_file)
s_id=file_name[:-4].replace('DD','')
df=pd.DataFrame.from_csv(tab_file, sep='\t')
df_2 = df.groupby(['special_name','ab']).size().reset_index(name='count')
#Here I wanted to create grouped barplots
ggplot(df_2, aes(x=('special_name'), y=('count'), fill=('ab'))) + geom_bar(stat='identity',position='dodge')
ax.set_title(s_id)
ax.set_xlabel('')
ax.set_ylabel('')
png_t = '%s/%s.b.png'%(out_folder,s_id)
plt.savefig(png_t, dpi = 500)
Ich habe es dann auch mit ggplot.ggplot() probiert, da kam dann die Meldung:
Code: Alles auswählen
AttributeError: Traceback (most recent call last)
<ipython-input-33-03dc98f5428a> in <module>()
100
101 #barplots
--> 102 ggplot.ggplot(df_2, aes(x=('special_name'), y=('count'), fill=('ab'))) + geom_bar(stat='identity',position='dodge')
Kann mir irgendjemand weiterhelfen?