omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Problems with Matplotlib

    Pythonista
    1
    1
    753
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ihf
      ihf last edited by

      I am trying to plot some data from an SQLITE db and I am having a problem with the data conversion:

      import sqlite3
      import time
      import datetime
      
      import numpy as np
      import matplotlib.pyplot as plt
      import matplotlib.dates as mdates
      
      conn = sqlite3.connect('acurite.sqlite')
      c = conn.cursor()
      
      sql = "SELECT * FROM acuriteHx"
      graphArray = []
      
      for row in c.execute(sql):
         startingInfo = str(row).replace(')','').replace('(','').replace('u\'','').replace("'","")
         splitInfo = startingInfo.split(',')
         graphArrayAppend = splitInfo[0] + ',' + splitInfo[2]
         graphArray.append(graphArrayAppend)
      #print(graphArray)
      datestamp, value = np.loadtxt(graphArray,delimiter=',', unpack=True,
                                   converters={ 0: mdates.datestr2num('%Y-%m-%d %H:%M:%S')})
      
      fig = plt.figure()
      
      rect = fig.patch
      
      sax1 = fig.add_subplot(1,1,1, axisbg='white')
      plt.plot_date(x=datestamp, y=value, fmt='b-', label = 'value', linewidth=2)
      plt.show()   ```
      
      When run with Python2.7 it crashes Pythonista and when run with Python3 it gives:
      
      Traceback (most recent call last):
       File "/private/var/mobile/Containers/Shared/AppGroup/4F06F35D-865B-4115-B827-BA053B3731EF/Pythonista3/Documents/sqliteplot.py", line 22, in <module>
         converters={ 0: mdates.datestr2num('%Y-%m-%d %H:%M:%S')})
       File "/var/containers/Bundle/Application/D78A900B-1E3B-4075-9CAB-F95408B28CD2/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/matplotlib/dates.py", line 283, in datestr2num
         dt = dateutil.parser.parse(d, default=default)
       File "/var/containers/Bundle/Application/D78A900B-1E3B-4075-9CAB-F95408B28CD2/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/dateutil/parser.py", line 749, in parse
         return DEFAULTPARSER.parse(timestr, **kwargs)
       File "/var/containers/Bundle/Application/D78A900B-1E3B-4075-9CAB-F95408B28CD2/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/dateutil/parser.py", line 311, in parse
         res, skipped_tokens = self._parse(timestr, **kwargs)
      TypeError: 'NoneType' object is not iterable
      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB Forums | Contributors