import matplotlib.pyplot as plt table_data = [["Zane",7], ["Bob",10], ["Jim",37], ["Stacey",21] ] # Prepare data for plotting names = [] values = [] #'row' successively contains each row from the above list for row in table_data: name = row[0] #Extracts Col 0 values with each iteration (Zane,Bone,Jim,Stacey) try: # row[1:] extracts from index 1 onward in the row i.e. 7,10,37,21 numeric_values = [float(val) for val in row[1:]] total = sum(numeric_values) names.append(name) values.append(total) except ValueError: print(numeric_values,"is non-numeric") continue # Plot scatter graph plt.figure(figsize=(8, 6)) #size in inches plt.scatter(names, values, color="blue", label="ScatterJT") #legend/data pt color, legend text plt.plot(names, values, color="orange", label="LineJT", marker="X") #color: legend text, line plt.title("Total Values by Name") plt.xlabel("Name") plt.ylabel("Total Value") plt.legend() #Displays a legend with the text "ScatterJT", "LineJT" plt.grid(True) #Adds lines to the horizontal & vertical grids plt.tight_layout() #Adjust spacing so text doesn't overlap or get cut off # ✅ Save to PDF BEFORE showing the plot plt.savefig("friends.pdf", format="pdf", bbox_inches="tight", dpi=300) print("Plot saved to friends.pdf") """ Co-Pilot explanation why this order is important When you use plt.show() in Python, it displays the plot on your screen. But in some environments — especially IDEs like PyCharm, VS Code, or Jupyter notebooks — showing the plot can also finalize or reset it behind the scenes. That means: The figure might be cleared or closed after it's shown. If you try to save it after plt.show(), there might be nothing left to save — resulting in a blank or missing file. 🧠 Think of it like this: Imagine you’re painting on a canvas. plt.show() is like hanging the painting on the wall. But in some studios, once it’s hung, the canvas gets wiped clean. So if you try to save it afterward, you’re saving a blank canvas. """ # Now show the plot plt.show()