I cannot get this code to connect the average points with a line. Would appreciate any help as i currently cannot figure out what to do in this situation.
here is the code:
def parse_icobi(icobilist: str) -> tuple[tuple[float, ...], tuple[float, ...]]:
"""
Parse ICOBI data from ICOBILIST.lobster.
Args:
icobilist (str): Path to ICOBILIST.lobster.
Returns:
tuple[tuple[float, ...], tuple[float, ...]]: The Fe-S and Si-S ICOBI values.
"""
co_s, si_s = [], []
with open(icobilist, 'r') as stream:
lines = stream.readlines()
stream.close()
markers = []
for idx, line in enumerate(lines):
if 'COBI#' in line:
markers.append(idx)
start, end = markers
for idx, line in enumerate(lines[start + 1:end]):
up = line.split()
symbol_i, symbol_j = up[1], up[2]
if 'Li' in symbol_j:
continue
down = lines[idx + 1 + end].split()
if 'Co' in symbol_i and 'S' in symbol_j:
co_s.append(float(up[-1]) + float(down[-1]))
elif 'S' in symbol_i and 'Si' in symbol_j:
si_s.append(float(up[-1]) + float(down[-1]))
return tuple(co_s), tuple(si_s)
def calculate_average(data):
averages = []
for num in num_lithium:
subset = [val for idx, val in enumerate(data) if x[idx] == num]
if subset:
avg = np.mean(subset)
else:
avg = np.nan
averages.append(avg)
return averages
parse_icobi('co_dos_py/Li0/ICOBILIST.lobster')
parse_icobi('co_dos_py/Li1-134/ICOBILIST.lobster')
parse_icobi('co_dos_py/Li2-130/ICOBILIST.lobster')
parse_icobi('co_dos_py/Li3-95/ICOBILIST.lobster')
parse_icobi('co_dos_py/Li7-2/ICOBILIST.lobster')
parse_icobi('co_dos_py/Li8-0/ICOBILIST.lobster')
paths = ['co_dos_py/Li0/ICOBILIST.lobster' ,'co_dos_py/Li1-134/ICOBILIST.lobster','co_dos_py/Li2-130/ICOBILIST.lobster','co_dos_py/Li3-95/ICOBILIST.lobster','co_dos_py/Li7-2/ICOBILIST.lobster','co_dos_py/Li8-0/ICOBILIST.lobster']
num_lithium = [0,1,2,3,7,8]
for iteration_count, path in enumerate(paths):
co_s, si_s = parse_icobi(path)
x = [num_lithium[iteration_count] for idx in range(len(co_s))]
z = [num_lithium[iteration_count] for idx in range(len(si_s))]
print (co_s, len(co_s))
print (si_s, len(si_s))
print ()
plt.scatter(x, co_s,s = 5, color='green',label= 'co_s')
plt.scatter(z, si_s, s = 5, color='purple',label='si_s')
avg_co = calculate_average(co_s)
avg_si = calculate_average(si_s)
plt.plot(num_lithium, avg_co, linestyle='--', color='green', marker='o', label='Average co_s')
plt.plot(num_lithium, avg_si, linestyle='--', color='purple', marker='o', label='Average si_s')
plt.ylabel("Bond covalency")
plt.gca().invert_xaxis()
plt.savefig('covalency_co.png', dpi=300)
plt.show()
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all 🙁
why isnt it letting me post this code i dont’get this website at all :
user25020285 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.