I am generating this plot. But the labels which I specify using plt.scatter(Time, Mean,color='black',marker="s",label="Numerics") and plt.plot(Time, monoExp(Time, m, t, b), '-', color='red',label="Fitted") are not appearing on the plot as shown in the current output. Any help would be greatly appreciated.
import pandas as pd
import numpy as np
from functools import reduce
import statistics
import csv
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import scipy.optimize
file_loc1 = f"C:\\Users\\USER\\OneDrive - Technion\\Research_Technion\\Python_PNM\\Sept14_2022\\Curve plotting\\Var_1\\10 iterations\\Mean_Std_NodesNotVisited.csv"
df = pd.read_csv(file_loc1)
Mean=df["Mean"].to_numpy()
# Mean=Mean.tolist()
print("Mean = ", Mean)
Std=df["Std"].to_numpy()
# Std=Std.tolist()
print("Std = ",Std)
file_loc2 = f"C:\\Users\\USER\\OneDrive - Technion\\Research_Technion\\Python_PNM\\Sept14_2022\\Curve plotting\\Var_1\\10 iterations\\1\\Data_220_beta_1e-1_48.25_51.75ND.csv"
df = pd.read_csv(file_loc2)
Time=df["t1"].to_numpy()
# Time=Time.tolist()
print("Time = ", Time)
def monoExp(x, m, t, b):
return m*np.exp(-t*x) + b
# perform the fit
p0 = (3,2,25)# start with values near those we expect
params, cv = scipy.optimize.curve_fit(monoExp, Time, Mean, p0)
print("params =",[params])
m, t, b = params
sampleRate = 100 # Hz
tauSec = (1 / t) / sampleRate
# determine quality of the fit
squaredDiffs = np.square(Mean - monoExp(Time, m, t, b))
squaredDiffsFromMean = np.square(Mean - np.mean(Mean))
rSquared = 1 - np.sum(squaredDiffs) / np.sum(squaredDiffsFromMean)
print(f"R² = {rSquared}")
plt.scatter(Time, Mean,color='black',marker="s",label="Numerics")
plt.errorbar(Time, Mean, Std,color='black',fmt='o', capsize=3) #, linestyle='None', fmt='-o')
# naming the x axis
plt.xlabel('Time',size=15)
# naming the y axis
plt.ylabel('% of nodes not visited',size=15)
plt.xlim(-0.2, 11)
plt.ylim(0, 30)
plt.plot(Time, monoExp(Time, m, t, b), '-', color='red',label="Fitted")
plt.title('var=1,beta=1e-1')
plt.show()
The current output is
