保存结果图的程序代码
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]plt.plot(x, y)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Sample Plot")# Save the figure
plt.savefig("sample_plot.png")
plt.show()
保存结果数据的程序代码
CSV格式
import csv
data = [['Name', 'Age'], ['Alice', 25], ['Bob', 30]]
with open('example.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
for row in data:
writer.writerow(row)
txt格式
with open('example.txt', 'w') as file:
file.write('Hello, World!')