How to plot dynamic graph using data from mysql in Python?

46
January 21, 2019, at 11:50 PM

I need to read data from an updating MySQL server, derive a variable and plot it.

The variable that I want to plot is not stored on the MySQL database, but can be derived from it. I have managed to write code that reads the database and derives the variable real time storing it in a dataframe. My issue is in trying to plot it. For each new update, I get a new graph, I do not need that. I need one continuously refreshing line graph. I could define another function that would plot data, but in python notebook you cannot run 2 cells at the same time. I am also quite new to python so do not know how to get around that.

I am not going to pass the whole code as it is quite involved and long ( the data derivation bit). The plotting bit, at then end of the derivation function, amounts to:

def get_data():
    mydb = mysql.connector.connect(
              host = '..'
              ...
              password = '...' )
    count = 1
    while (count<5):
        if count==1:
            ...
            'get this data like this'
            ...
        else:
            ...
            'get this data from here'
            ...
        rr = df[['id','request','timestamp',..]]
        plt.ion()
        plt.figure(figsize = (7,7))
        plt.plot(rr.RR, marker = 'o')
        plt.title('Live Risk Reversal Plot')
        plt.pause(1)
        plt.draw();
        count +=1
    mydb.close()

I expect a time series graph which updates after each new data derivation.

On a side note, it would be great if you could hint as to how I could show that graph on a website as well.

READ ALSO
How to decode octal escapes \303\241 to original utf-8 chars?

How to decode octal escapes \303\241 to original utf-8 chars?

I have a CSV file to import into the database, I found in many places string has encoded in "Mete y S\303\241cala" this manner

41
Can a database model prevent me from redirecting?

Can a database model prevent me from redirecting?

I am creating a webapp with Java Enterprise Edition and JSF

48
shorter way to check if an option exists

shorter way to check if an option exists

I hope there is a shorter way to check if an option inside sela exists

20
Looking for javascript library to save and restore html form, including restore from php&#39;s $_POST

Looking for javascript library to save and restore html form, including restore from php's $_POST

I am looking for a library to restore html form fields (inputs, selects, checkboxes and everything else) state using javascriptState of the form should be previously saved in php's $_POST data or other serialized format

48