Skip to content

Commit

Permalink
Tech Office P5
Browse files Browse the repository at this point in the history
  • Loading branch information
echedey-ls committed Nov 5, 2022
1 parent bfc538c commit d7cf8b7
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions Oficina Técnica/OT_regressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Author: Echedey Luis Álvarez
Date: 05/11/2022
Project: Technical Office graphs
File: OT_regressions.py
Abstract: just another grapher
Sources:
'''

import numpy as np
import matplotlib.pyplot as plt
import mplcyberpunk
import SciencePlots # Using my distribution, needs import
from scipy.stats import linregress

def main():
#plt.clf()
plt.style.use(['science'])
fig, ax = plt.subplots()

# Superior title
fig.suptitle('Regresiones de la demanda', **{'fontsize': 'x-large'})

x_months = np.array(['Enero','Febrero','Marzo','Abril','Mayo','Junio',
'Julio','Agosto','Septiembre','Octubre','Noviembre',
'Diciembre'])

y_ene_jun = np.array([500, 510, 530, 535, 542, 570])
y_jul_dic = np.array([950, 970, 1000, 1050, 1075, 1100])

# Meses menor demanda
x = np.arange(0,6)
y = y_ene_jun

ax.bar(x_months[:6], y, edgecolor="k",
label='Demanda: meses de menor demanda')
regLine = linregress(x, y)
regLx = [min(x), max(x)]
regLy = [regLine.slope * regLx[0] + regLine.intercept, regLine.slope * regLx[-1] + regLine.intercept]
print(rf'D= {regLine.slope:.4f}·(i_mes)+{regLine.intercept:.4f}')
plt.plot(
regLx,
regLy,
color= 'mediumorchid',
linestyle= 'dashed',
linewidth = '5',
label= 'Regresión lineal: meses de menor demanda'
)

# Meses de mayor demanda
x = np.arange(6,12)
y = y_jul_dic

ax.bar(x_months[6:], y, edgecolor="k",
label='Demanda: meses de mayor demanda')
regLine = linregress(x, y)
regLx = [min(x), max(x)]
regLy = [regLine.slope * regLx[0] + regLine.intercept, regLine.slope * regLx[-1] + regLine.intercept]
print(rf'D= {regLine.slope:.4f}·(i_mes-6)+{regLine.intercept:.4f}')
plt.plot(
regLx,
regLy,
color= 'crimson',
linestyle= 'dashed',
linewidth = '5',
label= 'Regresión lineal: meses de mayor demanda'
)

ax.set_xticks(np.arange(0,12))
ax.set_xticklabels(x_months)

plt.xlabel(r'Mes')
plt.ylabel(r'Demanda')
plt.grid()
plt.legend()

# mplcyberpunk.add_glow_effects()

plt.tight_layout()
# plt.savefig('some_title.png')
plt.show()

if __name__ == '__main__':
main()
print('☭Data was analyzed successfully. Have a nice day☭')

0 comments on commit d7cf8b7

Please sign in to comment.