Is it possible to move the colored points from the general legend to the text

import os
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

# Specify the folder paths
input_folder = r"C:\Users\samuel.hernandez\OneDrive - FUNDECYT - PCTEX\Escritorio\Doctorado\Experimental\TGA"
output_folder = r"C:\Users\samuel.hernandez\OneDrive - FUNDECYT - PCTEX\Escritorio\Doctorado\Experimental\TGA\Python\Test"

# Ensure the output folder exists
os.makedirs(output_folder, exist_ok=True)

def read_data_from_file(file_path):
    encodings = ['utf-8', 'iso-8859-1', 'cp1252']
    for encoding in encodings:
        try:
            data = pd.read_csv(file_path, delim_whitespace=True, skiprows=1, encoding=encoding)
            
            temp_col = data.columns[1]  # Assuming temperature is the second column
            weight_col = data.columns[4]  # Assuming weight is the fifth column
            
            x_data = data[temp_col].str.replace(',', '.').astype(float)
            y_data = data[weight_col].str.replace(',', '.').astype(float)
            
            return x_data, y_data
        except (UnicodeDecodeError, pd.errors.EmptyDataError, KeyError):
            continue
    
    raise ValueError(f"Unable to read the file {file_path} with any of the attempted encodings.")

def calculate_mass_loss_at_200(x_data, y_data):
    initial_mass = y_data.iloc[0]
    mass_at_200 = np.interp(200, x_data, y_data)
    mass_loss = initial_mass - mass_at_200
    return mass_loss, mass_at_200  # Return both mass loss and mass at 200°C

def create_graph(files, title):
    plt.figure(figsize=(18, 10))  # Increased figure width to accommodate larger legends

    mass_loss_labels = []
    vertical_spacing = 10  # Constant space difference for vertical separation
    molecular_weight = 313.7739  # Molecular weight of the compound in g/mol
    molecular_weight_H2O = 18.015  # Molecular weight of water in g/mol

    # Keep track of lines and markers for the legend
    lines_for_legend = []
    markers_for_legend = []

    for i, file_name in enumerate(files):
        file_path = os.path.join(input_folder, file_name)
        try:
            x_data, y_data = read_data_from_file(file_path)
            label = file_name.replace('.txt', '').replace('!', '')

            mass_loss, mass_at_200 = calculate_mass_loss_at_200(x_data, y_data)
            mass_loss_percentage = (mass_loss / y_data.iloc[0]) * 100  # Calculate percentage of mass loss
            
            # Calculate the mass of water based on the mass loss percentage
            mass_of_water = (mass_loss_percentage / 100) * molecular_weight  # Mass of water in grams
            
            # Calculate the number of moles of water
            moles_of_water = mass_of_water / molecular_weight_H2O  # Moles of water
            
            # Format the number of moles for display
            moles_of_water_str = f"{moles_of_water:.2f}"  # Format to two decimal places

            # Use a vibrant colormap for distinct colors
            line_color = plt.cm.tab10(i % 10)  # Use the tab10 colormap for colors
            line, = plt.plot(x_data, y_data, label=label, color=line_color)
            lines_for_legend.append(line)

            # Mark the point at 200 °C with a smaller symbol
            dot_y_value = np.interp(200, x_data, y_data)
            marker, = plt.plot(200, dot_y_value, marker='o', color=line_color, markersize=5, linestyle='')
            markers_for_legend.append(marker)

            # Append the mass loss percentage and number of molecules to the labels
            mass_loss_labels.append(f'{label}: {mass_loss_percentage:.2f}% (≈ {moles_of_water_str} molecules of H₂O)')

        except ValueError as e:
            print(f"Error reading {file_name}: {str(e)}")

    plt.xlabel('Temperature (°C)', fontsize=12)
    plt.ylabel('Weight (%)', fontsize=12)

    # Create the main legend (sample names with circles)
    plt.legend(handles=[plt.Line2D([0], [0], color=line.get_color(), marker='o', markersize=5, label=line.get_label()) 
                        for line, marker in zip(lines_for_legend, markers_for_legend)],
               bbox_to_anchor=(1.05, 0.5), loc='center left', borderaxespad=0., 
               fontsize='medium', frameon=False)

    # Add mass loss legend inside the graph on the left with a black square border
    mass_loss_text = "Mass loss\n" + "\n".join(mass_loss_labels)
    plt.text(0.05, 0.5, mass_loss_text, transform=plt.gca().transAxes, 
             verticalalignment='center', fontsize='medium', 
             bbox=dict(boxstyle='square', facecolor='white', edgecolor='black', alpha=0.8))

    # Adjust layout to prevent legends from being cut off
    plt.tight_layout()
    plt.subplots_adjust(right=0.8, left=0.1)

    output_path = os.path.join(output_folder, f'{title}.png')
    plt.savefig(output_path, dpi=300, bbox_inches='tight')
    plt.close()
    print(f"Graph saved: {output_path}")

# Get all txt files in the folder
txt_files = [f for f in os.listdir(input_folder) if f.endswith('.txt')]

# Categorize files
h_files = [f for f in txt_files if 'H' in f and not f.startswith('!Mn')]
c_files = [f for f in txt_files if 'C' in f]
mn_h_files = [f for f in txt_files if 'H' in f and f.startswith('!Mn')]

# Create graphs
create_graph(h_files, 'H_containing_samples')
create_graph(c_files, 'C_containing_samples')
create_graph(mn_h_files, 'Mn_H_containing_samples')

print("All graphs have been created and saved.")
print(f"H files: {h_files}")
print(f"C files: {c_files}")
print(f"Mn-H files: {mn_h_files}")