Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1.  
  2. import collections
  3. import operator
  4. import matplotlib.pyplot as plt
  5. from pandas.plotting import register_matplotlib_converters
  6. register_matplotlib_converters()
  7.  
  8. # Считаем суммарную выручку в каждый день
  9. orders_count = {}
  10. for d, income in zip(data.date, data.total):
  11.     if d not in orders_count.keys():
  12.         orders_count[d] = income
  13.     else:
  14.         orders_count[d] += income
  15.  
  16. sorted_orders = collections.OrderedDict(sorted(orders_count.items(), key=operator.itemgetter(0)))
  17.  
  18. # нарисуем график с помощью Plotly
  19. fig = go.Figure()
  20. fig.add_trace(go.Scatter(x=list(sorted_orders.keys()),
  21.                          y=list(sorted_orders.values()),
  22.                          mode='lines',
  23.                          name='График количества ежедневных заказов за 2017-2019 годы')
  24.              )
  25. fig.update_layout(
  26.     height=750,
  27.     paper_bgcolor="#FFFFFF",
  28.     margin=go.layout.Margin(l=100, r=30, b=80, t=90, pad=4),
  29.     title=go.layout.Title(
  30.         text="График количества ежедневных заказов за 2017-2019 годы",
  31.         xref="paper",
  32.         x=0
  33.     ),
  34.     xaxis=go.layout.XAxis(
  35.         title=go.layout.xaxis.Title(
  36.             text="Время",
  37.         )
  38.     ),
  39.     yaxis=go.layout.YAxis(
  40.         title=go.layout.yaxis.Title(
  41.             text="Количество заказов в день",
  42.         )
  43.     )
  44. )
  45. fig.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement