Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.dates as mdates
  4. from matplotlib import pyplot as plt
  5. plt.style.use(['dark_background'])
  6.  
  7. # + ECHT.UEBERSEE-RUM... (ID = 6)
  8. # + GALLO  ZINFANDEL... (ID = 55)
  9. # - TOILETTENPAPIER 3... (ID = 38)
  10.  
  11.  
  12. plt.rcParams.update({'font.size': 18})
  13. artikel_df = pd.read_csv('./data_new/REWE_ARTIKEL.csv')
  14. artikel = 55
  15. markt = 4
  16. artikel_name = artikel_df.loc[artikel_df['ARTIKEL'] == artikel, 'BEZEICHNUNG'].values[0]
  17. where_condition = "ARTIKEL ==" + str(artikel) + " AND MARKT == " + str(markt) + \
  18.                 " AND KAL_TAG > '2017-12-31' AND GESCHLOSSEN == 0"
  19.  
  20. df = prediction.where(where_condition).select("KAL_TAG", "ABVERKAUF_STK", "PREDICTION", "diff").orderBy("KAL_TAG").toPandas()
  21. #.where("KAL_TAG > '2017-31-12'")
  22.  
  23. y_1 = list(df["ABVERKAUF_STK"])
  24. y_2 = list(df["PREDICTION"])
  25. y_3 = list(df["diff"])
  26.  
  27. x = list(df["KAL_TAG"])
  28.  
  29. #fig, ax = plt.subplots(figsize=(16, 9))
  30. #for idx, x_i in enumerate(x):
  31. #    if y_3[idx] >= 0:
  32. #        col = 'green'
  33. #    else:
  34. #        col = 'red'
  35. #    ax.plot((x_i, x_i), (y_1[idx], y_2[idx]), c=col)
  36.  
  37. fig, ax = plt.subplots(figsize=(16, 9))
  38. ax.plot(x, y_1, alpha=0.8)
  39. ax.fill_between(x,y_1, alpha=0.5)
  40. ax.plot(x, y_2, alpha=0.8)
  41. #ax.scatter(x, y_3)
  42. #ax.scatter(x, y_3, color='cyan')
  43. #ax.set_xlim(0, 500)
  44. #ax.set_ylim(0, 1)
  45. ax.grid(True, axis='y')
  46. ax.set_axisbelow(True)
  47. #ax.set_xticks(np.arange(0, 1.001, 0.1))
  48. #ax.set_yticks(np.arange(0, 1.001, 0.1))
  49. month_fmt = mdates.DateFormatter('%b')
  50. months = mdates.MonthLocator()
  51. ax.xaxis.set_major_locator(months)
  52. ax.xaxis.set_major_formatter(month_fmt)
  53. #for tick in ax.get_xticklabels():
  54. #    tick.set_rotation(65)
  55. #myFmt = mdates.DateFormatter('%y')
  56. #ax.xaxis.set_major_formatter(myFmt)
  57. #fig.autofmt_xdate()
  58. #ax.set_xlabel(x[2].year)
  59. ax.set_ylabel('Sale in quantity')
  60. ax.set_title(artikel_name)
  61. ax.legend(['Actual sale', 'Predicted sale'], loc='upper right')
  62. plt.savefig(str(artikel) + '_' + str(markt) + '_sales_2018.png', transparent=True)
  63. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement