import xml.etree.ElementTree as ET import pandas as pd import matplotlib.pyplot as plt # Parse the XML file tree = ET.parse('4spots 160um 400um 6x20.xml') root = tree.getroot() # Extract data and store in a list of dictionaries samples = [] for sample in root.findall('Sample'): sample_data = { 'SampleNumber': int(sample.find('SampleNumber').text), 'SpotNumber': int(sample.find('SpotNumber').text), 'SpotRow': int(sample.find('SpotRow').text), 'SpotCol': int(sample.find('SpotCol').text), 'SampleLabel': sample.find('SampleLabel').text, 'Depositions': int(sample.find('Depositions').text) } samples.append(sample_data) # Convert to DataFrame df = pd.DataFrame(samples) # Print the DataFrame print(df) # Visualize spot positions on a grid plt.figure(figsize=(8, 6)) plt.scatter(df['SpotCol'], df['SpotRow'], s=100, c=df['SampleNumber'], marker='o') # Annotate spots with their labels for i, label in enumerate(df['SampleLabel']): plt.annotate(label, (df['SpotCol'][i], df['SpotRow'][i]), textcoords="offset points", xytext=(0,10), ha='center') plt.gca().invert_yaxis() # Invert y-axis to match typical grid layout plt.xlabel('SpotCol') plt.ylabel('SpotRow') plt.title('Spot Positions on Grid') plt.grid(True) plt.gca().set_aspect('equal', adjustable='box') plt.show()