让我改进一下你的代码:import numpy as np
import matplotlib.pyplot as plt
# set the font size globally to get the ticklabels big too:
plt.rcParams["font.size"] = 16
# use numpy to read in the names
names = np.genfromtxt("selected.csv", delimiter=" ", dtype=np.str, skiprows=1)
# not necessary butyou might want to add options to the figure
plt.figure()
# don't use a for i in range loop to loop over array elements
for name in names:
# use the format function
filename = '/home/mh/Masters_Project/Sigma/{}.dat'.format(name)
# use genfromtxt because of better error handling (missing numbers, etc)
average, sigma = np.genfromtxt(filename, usecols = (0,1), unpack = True, delimiter = ' ')
plt.xlabel('Magnitude(average)')
plt.ylabel('$\sigma$')
plt.plot(average, sigma, marker = '+', linestyle = '', label = name)
plt.legend(loc = 'best')
plt.show()