
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import ticker
import numpy as np

def SeriePonderee(list,effectif):
    n= len(list)

    T=[]
    for i in range(n):
        m=effectif[i]
        for j in range(m):
            T.append(list[i])

    return T

x=[1,2,3,4,5]
y=[10,5,6,7,9]
z=[9,8,5,11,10]



Y=SeriePonderee(x,y)
Z=SeriePonderee(x,z)
print(Z)

# plt.figure(1, figsize=(12,10), dpi=100)
plt.figure(1, figsize=(10,8), dpi=100)
left = 0.125  # the left side of the subplots of the figure
right = 0.9   # the right side of the subplots of the figure
bottom = 0.1  # the bottom of the subplots of the figure
top = 0.9     # the top of the subplots of the figure
wspace = 0.2  # the amount of width reserved for space between subplots,
              # expressed as a fraction of the average axis width
hspace = 0.35  # the amount of height reserved for space between subplots,
              # expressed as a fraction of the average axis height


plt.subplot(231)
plt.axis([0,6,0,13])
plt.plot(x,y,'ro')
plt.plot(x,z,'ob')
plt.grid()
plt.legend(['y','z'])
plt.title("Nuage de points")

axe2=plt.subplot(232)

axe2.spines['top'].set_visible(False)
axe2.spines['right'].set_visible(False)


width=0.4
x1=[i for i in x]
x2=[i+width for i in x]


p1=plt.bar(x1,y,width)
p2=plt.bar(x2,z,width)
plt.bar_label(p1, padding=3)
plt.bar_label(p2, padding=3)
plt.title("Diagrammes en bâtons")
plt.legend(['y','z'])

axe3=plt.subplot(233)

axe3.spines['top'].set_visible(False)
axe3.spines['right'].set_visible(False)

Y=SeriePonderee(x,y)
Z=SeriePonderee(x,z)
# plt.hist(Y, bins = [1,3,4,5], color = 'yellow',
            # edgecolor = 'red')
plt.hist([Y,Z], bins = [1,3,4,5], color = ['yellow','blue'],
            edgecolor = 'red')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Exemple d\' histogramme simple')
plt.legend('y')

axe4=plt.subplot(234)
explode = (0, 0.2, 0, 0, 0)  # on isole seulement la deuxième part


axe4.spines['top'].set_visible(False)
axe4.spines['right'].set_visible(False)
plt.pie(y, labels=['1','2','3','4','5'], explode=explode,
       autopct='%1.1f%%', shadow=True, startangle=90)
plt.ylabel('y')
plt.title('Exemple de diagramme circulaire ')


axe5=plt.subplot(235)

axe5.xaxis.labelpad = 0.5
axe5.yaxis.labelpad = 1

axe5.spines['top'].set_visible(False)
axe5.spines['right'].set_visible(False)
axe5.spines['left'].set_position('zero')
axe5.spines['bottom'].set_position('zero')
axe5.set_aspect('equal')

major_ticks = np.arange(-2, 2, 1)
minor_ticks = np.arange(0, 5, 1)

axe5.set_xticks(major_ticks)
axe5.set_xticks(minor_ticks, minor=True)
axe5.set_yticks(major_ticks)
axe5.set_yticks(minor_ticks, minor=True)

axe5.grid(which='minor', alpha=0.2)
axe5.grid(which='major', alpha=0.5)
# plt.yticks(np.arange(0,4,0.5))
# plt.xticks(np.arange(-2,2,0.5))

axe5.grid(color='gray', linestyle='dashed', linewidth=.5,which='both')
x=np.arange(-2,2,0.1)
y=[t**2 for t in x]
plt.plot(x,y,'r-')

plt.text(1.5,3.5, 'y=x^2',color='blue',backgroundcolor='yellow')
# plt.legend('y=f(x)')
plt.title("Représentation d'une fontion")


axe6=plt.subplot(236)

plt.ylim(-1, 6)
# plt.boxplot(Y,Z,positions = [1, 3 ])

plt.boxplot([Y,Z], sym = 'g*', whis = 2,
                                 widths = [ 0.5,0.5], positions = [1, 3],
                                 patch_artist = True)
axe6.xaxis.set_ticklabels(['y', 'z'])
plt.title("Boîtes à moustaches")



plt.show()