<jupyter_start><jupyter_text>Example data<jupyter_code>x_vals = [0, 1, 2, 3, 4, 5]
y_vals = [0, 1, 3, 2, 3, 5]<jupyter_output><empty_output><jupyter_text>"Normal" plot<jupyter_code>plt.plot(x_vals, y_vals)

plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>To create "animated" graphics, we need to:1. have a "values"-generator2. to import the FuncAnimation from matplotlib3. Use this function to create the graphOk. Let's first import what we need...<jupyter_code>from matplotlib.animation import FuncAnimation<jupyter_output><empty_output><jupyter_text>Now define a function to generate some "sample" data in the fly<jupyter_code>x_vals = []
y_vals = []

index = count()

def animate1(i):
    x_vals.append(next(index))
    y_vals.append(random.randint(0, 5))
    
    plt.plot(x_vals, y_vals)<jupyter_output><empty_output><jupyter_text>and finally, lets define this as the animation for the graphic.**Note:** Be sure to **Stop Interaction** on previous plot, or else this will not work, or work "funky"...<jupyter_code>ani = FuncAnimation(plt.gcf(), animate1, interval=1000)<jupyter_output><empty_output><jupyter_text>The problem (as is) is that the lines are changing colors, and that's because we are in reality, just drawing multiple lines, all above each other...We need to delete the previous values, before drawing new ones...<jupyter_code>x_vals = []
y_vals = []

index = count()

def animate2(i):
    x_vals.append(next(index))
    y_vals.append(random.randint(0, 5))
    
    plt.cla()
    plt.plot(x_vals, y_vals)
ani = FuncAnimation(plt.gcf(), animate2, interval=1000)<jupyter_output><empty_output><jupyter_text>Ok, let's use some real data...The "real" data is a CSV file, generated by a Python script (see `data_gen.py` file).<jupyter_code>index = count()

def animate3(i):
    data = pd.read_csv('data09.csv')
    x = data['x_value']
    y1 = data['total_1']
    y2 = data['total_2']
        
    plt.cla()
    plt.plot(x, y1, label='Channel 1')
    plt.plot(x, y2, label='Channel 2')
    plt.legend(loc='upper left')

    plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Before ploting the data below, please run the file `data_gen.py`, by goind the the command line and running```bashpython data_gen.py```<jupyter_code>ani = FuncAnimation(plt.gcf(), animate3, interval=1000)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13183552352691819, 'fraction_numerical': 0.019923696481559984, 'mean_word_length': 5.344086021505376, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '405465', 'license': 'MIT', 'n_tokens_mistral': 891, 'n_tokens_neox': 836, 'n_words': 214, 'path': '09. LiveData.ipynb', 'repo_name': 'pmguerre/matplotlib_tutorial', 'size': '2359'}