import matplotlib.pyplot as my_graph
import matplotlib.dates as mdates
def several_tag(tags):
mmin=[]
mmax=[]
current_db=r.hget('db_id', 'value')
data=db_arch[current_db]
for ctag in tags:
vals=[]
times=[]
tag_values=data.find({'tagname':ctag},{'value':1,'time':1,'_id':0})
for tag in tag_values:
try:
vals.append(round(float(tag['value']),2))
except:
vals.append(0)
times.append(datetime.fromtimestamp(tag['time']))
mmin.append(min(vals))
mmax.append(max(vals))
my_graph.ylim(min(mmin)-5,max(mmax)+5)
my_graph.plot(times, vals)
axes = my_graph.subplot(1, 1, 1)
axes.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M:%S"))
locator=mdates.ticker.FixedLocator([mdates.date2num(times[vals.index(min(vals))]),mdates.date2num(times[vals.index(max(vals))])])
axes.xaxis.set_major_locator(locator)
my_graph.xticks(size="xx-small", color="gray")
my_graph.annotate('max: %s' % max(vals), size="x-small", color="red", xy=(mdates.date2num(times[vals.index(max(vals))]), max(vals)), xycoords='data', xytext=(10, 10), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))
my_graph.annotate('min: %s' % min(vals), size="x-small", color=(0.4, 0.5, 0.3), xy=(mdates.date2num(times[vals.index(min(vals))]), min(vals)), xycoords='data', xytext=(15, -15), textcoords='offset points', arrowprops=dict(arrowstyle='-|>'))
my_graph.grid(True)
my_graph.savefig(r'1.png', transparent=True)
several_tag(['MKA50GE004ZQ_V', 'MKA50GE003ZQ_V'])
http://rghost.net/48775269.view - результат быдлокода.
Как сделать отметки экстремальных значений на временной линейке для обоих графиков?