我有几个 .csv 文件,我想从这些文件中绘制图表。这些文件包含两列,每个 csv 文件的第一列相同。
文件1.csv:
20 -4.140462670
25 -4.140537060
30 -4.140571620
35 -4.140581580
40 -4.140584350
Run Code Online (Sandbox Code Playgroud)
文件2.csv:
20 -4.140468880
25 -4.140542900
30 -4.140577590
35 -4.140587560
40 -4.140590330
Run Code Online (Sandbox Code Playgroud)
我尝试使用下面的脚本来绘制第一个:
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
with open('file1.csv') as f:
f=[x.strip() for x in f if x.strip()]
data=[tuple(map(float,x.split())) for x in f[0:]]
oX=[x[0] for x in data]
oY=[x[1] for x in data]
plt.figure(figsize=(9,6))
ax = plt.subplot(111)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.4f'))
ax.plot(oX, oY, color='blue', linestyle='dashdot', linewidth=2, marker='o', markerfacecolor='red', markeredgecolor='black',markeredgewidth=2, markersize=6)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但我想绘制一个包含两条曲线(file1.csv 和 …