A
A
Alex F2018-03-20 10:06:17
Python
Alex F, 2018-03-20 10:06:17

Why doesn't matplotlib draw a line?

Welcome all.
The code is of course hellish, I'm experimenting :)

Actually here:
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
import json
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np
import time, json
import warnings
warnings.filterwarnings("ignore")

###############################################
localtime = time.localtime(time.time())
thistime = localtime[3]

################################################

with open('/home/vns.json') as json_data:
    data = json.load(json_data)  #
    json_data.close()
#############################################	

t = 0;sr = 0; st = 0; mnrx = []; tgr = []
while t < thistime:
  rx = round(data['interfaces'][0]['traffic']['hours'][t]['rx'] / 1024, 2)
  mnrx += [rx]
  tgr += [t]
  sr += rx
  t = t + 1
  sr = round(sr, 2)
  srout = [sr]
  lstrx = set(mnrx)

  yy = 0
  for uu in lstrx:
    nn = 0

    for uu in lstrx:
      if uu > uu:
        nn += 1
    if nn < len(lstrx) - 1:
      yy = uu
      break
#############################################
locatorx = matplotlib.ticker.LinearLocator(23)
locatory = matplotlib.ticker.LinearLocator(10)
dpi = 96
fig = plt.figure(dpi = dpi, figsize = (600 / dpi, 200 / dpi), facecolor='#cccccc')
plt.rcParams.update({'font.size': 8})


plt.xlabel(f'{thistime} часов')
plt.ylabel(f'{sr} Mb')

ax1 = plt.subplot(211)
ax1.title.set_color('red')
ax1.set_title('Расход трафика')
ax1.axis([0, 23, 0, yy*3])			
lines = plt.plot([tgr], [mnrx], 'g^', label = 'rx', color='#AA0000', lw=1)
ax1.grid(True)
ax1.legend(loc = 'best', fancybox=True, framealpha=0.3)

ax2 = plt.subplot(212)
ax2.axis([0, 23, 0, yy*3])
lines = plt.plot([tgr], [mnrx], 'o', label = 'tx', color='#00AA00', lw=1)
ax2.xaxis.set_major_locator(locatorx)
ax2.yaxis.set_major_locator(locatory)
ax2.grid()
ax2.legend(loc = 'best', fancybox=True, framealpha=0.3)
ax2.tick_params( axis='x', bottom='off', top='off', labelbottom='off')
ax2.tick_params( axis='y', bottom='off', top='off', labelbottom='off')

plt.savefig('graf.png', transparent=True)
plt.show()
plt.clf()
print (mnrx)
print (lstrx)
print ("----------------------\n",yy*3)


When replaced with, say, plt.plot([tgr], [mnrx], '-' , it just doesn't print anything.
How can I overcome this and draw lines?
s_1521528717_4650712_bce4aa524a.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question