File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ __author__ = 'ipetrash'
5+
6+
7+ # pip install matplotlib
8+ import matplotlib .pyplot as plt
9+ import matplotlib .dates as mdates
10+
11+
12+ from db import MetalRate
13+ from parser import MetalEnum
14+
15+
16+ DATE_FORMAT = '%d/%m/%Y'
17+
18+
19+ # TODO: поддержать и другие металлы
20+ days = []
21+ values = []
22+ for metal_rate in MetalRate .select ().where (MetalRate .metal == MetalEnum .Gold ):
23+ days .append (metal_rate .date )
24+ values .append (metal_rate .amount )
25+
26+
27+ plt .gca ().xaxis .set_major_formatter (mdates .DateFormatter (DATE_FORMAT ))
28+ plt .gca ().xaxis .set_major_locator (mdates .YearLocator (3 ))
29+
30+ plt .plot (days , values )
31+
32+ title = f"Стоимость грамма золота в рублях за { days [0 ].strftime (DATE_FORMAT )} - { days [- 1 ].strftime (DATE_FORMAT )} "
33+ plt .xlabel (title )
34+
35+ plt .gcf ().autofmt_xdate ()
36+
37+ plt .show ()
You can’t perform that action at this time.
0 commit comments