Je cherche le code pour mettre les 4 graphiques dans une seule fenetre.
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
data={'Label':[ -1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1],
'Dseff':[ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
'champ_major_minor':[ 0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1],
'budget_delta2':[ 0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100],
'P':[ 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3]}
df_ini=pd.DataFrame(data)
CST_PLAY=5
p=4
label='test'
while p < CST_PLAY:
i=0
j=0
for i in range(2):#df_ini.champ_major_minor
if i==0 :
label_i="champ: minor"
else:
label_i="champ: major"
for g in [0,100]:#df_ini.budget_delta2
if g==0 :
label_g="budg: equivalent(<qtl(0.5))"
else:
label_g="budg: bcp diff"
fig=plt.figure()
fig, ax1=plt.subplots()
ax2=ax1.twinx()
df_ini_debut_saison=df_ini[(df_ini.P<p)&(df_ini.champ_major_minor== i)&(df_ini.budget_delta2== g)]
df_ini_debut_saison.groupby(['Dseff'])[['Label']].count().unstack().plot(ax=ax2,stacked= True,style='k--')
(df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count()/df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count().groupby(level=0).sum()).unstack().plot(ax=ax1,kind='bar', stacked= True, alpha=0.5,title="Nb de Play " + str(p)+ " Nb Match : " + str(len(df_ini_debut_saison)) + "\n " + label_i + "// " + label_g)#title="Nb de Play " + str(p)
ax1.annotate(label,xy=(0,0),xytext=(0,-0.25))
# if len(df_ini_debut_saison)>0:
# df_ini_debut_saison.groupby(['Dseff'])[['Label']].count().unstack().plot(ax=ax2,stacked= True,style='k--')
# (df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count()/df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count().groupby(level=0).sum()).unstack().plot(ax=ax1,kind='bar', stacked= True, alpha=0.5,title="Nb de Play " + str(p)+ " Nb Match : " + str(len(df_ini_debut_saison)) + "\n " + label_i + "// " + label_j)#title="Nb de Play " + str(p)
# ax1.annotate(label,xy=(0,0),xytext=(0,-0.25))
p+=1
Malgré le code suivant que j'ai trouvé, je n'arrive pas à l'adapter:
fig, axes=plt.supblots(2,2,sharex=True,sharey=True)
for i in range(2):
for j in range(2):
axes[i,j].hist(randn(500, bins=50, color='k', alpha=0.5)
plt.subplots_adjust(wspace=0,hspace=0)
import pandas as pd
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.style as style
print(style.available)
style.use('seaborn-poster')#('fivethirtyeight')
data={'Label':[ -1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1],
'Dseff':[ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
'champ_major_minor':[ 0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1],
'budget_delta2':[ 0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100,0,0,0,0,0,0,100,100,100,100,100,100],
'P':[ 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3]}
df_ini=pd.DataFrame(data)
CST_PLAY=5
p=4
label='test'
while p < CST_PLAY:
fig=plt.figure()
gs=fig.add_gridspec(2,2)
i=0
j=0
for i in range(2):#df_ini.champ_major_minor
if i==0 :
label_i="champ: minor"
else:
label_i="champ: major"
for g in [0,100]:#df_ini.budget_delta2
if g==0 :
label_g="budg: equivalent(<qtl(0.5))"
else:
label_g="budg: bcp diff"
j=g
j/=100
ind=i+j+1
print(str(ind))
ax1=fig.add_subplot(gs[int(i),int(j)])
ax2=ax1.twinx()
df_ini_debut_saison=df_ini[(df_ini.P<p)&(df_ini.champ_major_minor== i)&(df_ini.budget_delta2== g)]
df_ini_debut_saison.groupby(['Dseff'])[['Label']].count().unstack().plot(ax=ax2,stacked= True,style='k--')
(df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count()/df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count().groupby(level=0).sum()).unstack().plot(ax=ax1,kind='bar', stacked= True, alpha=0.5,title="Nb Journée " + str(p)+ " Nb Matchs : " + str(len(df_ini_debut_saison)) + "\n " + label_i + "// " + label_g)#title="Nb de Play " + str(p)
# (df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count()/df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count().groupby(level=0).sum()).unstack().plot(kind='bar', stacked= True, alpha=0.5,title="Nb de Play " + str(p)+ " Nb Match : " + str(len(df_ini_debut_saison)) + "\n " + label_i + "// " + label_g)#title="Nb de Play " + str(p)
ax1.annotate(label,xy=(0,0),xytext=(0,-0.25))
# if len(df_ini_debut_saison)>0:
# df_ini_debut_saison.groupby(['Dseff'])[['Label']].count().unstack().plot(ax=ax2,stacked= True,style='k--')
# (df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count()/df_ini_debut_saison.groupby(['Dseff','Label'])[['Label']].count().groupby(level=0).sum()).unstack().plot(ax=ax1,kind='bar', stacked= True, alpha=0.5,title="Nb de Play " + str(p)+ " Nb Match : " + str(len(df_ini_debut_saison)) + "\n " + label_i + "// " + label_j)#title="Nb de Play " + str(p)
# ax1.annotate(label,xy=(0,0),xytext=(0,-0.25))
p+=1
- Edité par JeromeBonneval 29 juillet 2019 à 17:09:11
Jérôme Bonneval
Matplotlib
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Jérôme Bonneval
Jérôme Bonneval
Jérôme Bonneval