Interactive graph

Hello everyone,

I have a dataset with a LOT of data, it’s only two columns: the time and the position.

I display them with scatter, but it takes a great amount of time when I try to zoom in or to move inside the graph (because the dataset is very big).

I would like to:

  • display only a section of the data: the user would be able to move smoothly from sections to sections by pressing the right or left arrow on his keyboard
  • that only the data shown are loaded by the software, so it takes less of the RAM

In fact, it is not just the two columns time and position that I want to display. Currently I also highlight some values of the graph in green with axvspan or in yellow with add_patch(Rectangle). I would like to do it too.

What would you suggest ?

Thank you very much,

Léa

Say you have the master data set that holds all time and all corresponding data values. You can then have the user enter a starting and ending time stamp value. From this information, the script then obtains the corresponding information (time and data) from the master data set. It then plots this data as per your requirement.

You can do this fairly easy with a for loop and conditional statement, and two extra lists to write the information to.

Hi Paul, thank you for your answer.

I’ve already done that : the user can choose to see all the dataset or just a part as you say.

But I would like the graph to open on the first section of the data (with 200 points for exemple) and that the user can move in the data by clicking on the right or left arrow of his keyboard to see the other sections. The user could go back and forth only with the arrows.

What it appears that you want to do is bind keys to four distinct functions - one each per specific funtionality. Assuming you’re using tkinter as your GUI library, it is something like this (else modify for your specific GUI library):

def up_data(*args):
    #    statements here to move plot up by 200 data points

def down_data(*args):
    #    statements here move plot down by 200 data points

def left_data(*args):
    #    statements here move plot left by 200 data points

def right_data(*args):
    #    statements here move plot right by 200 data points

# here, "root" is your `app`
root.bind('<Up>', up_data)
root.bind('<Down>', down_data)
root.bind('<Left>', left_data)
root.bind('<Right>', right_data)

This is a rough intro but the basis stands. In each function, you will have to enter code such that it updates the graph per requirement.

To update the graph dynamically, you can referefence the following tutorial and see how you can incorporate the ideas discussed into your application.

I would start with creating one function first. Once you have verified that it works as expected, you can proceed with creating the remaining three.