Skip to content

Instantly share code, notes, and snippets.

@basavyr
Created February 19, 2022 18:21
Show Gist options
  • Save basavyr/341b210d7328f5df10be1b7bb28ef65e to your computer and use it in GitHub Desktop.
Save basavyr/341b210d7328f5df10be1b7bb28ef65e to your computer and use it in GitHub Desktop.
create text label in python using scaled centering (relative to the plot size)
def ShowSolutions(n, id):
nqReduced = 4
nqM = 100
for i in range(n):
plotname = pathPrefix+foldername + 'plot-id'+str(i+1)+'.pdf'
fig, ax = plt.subplots()
plt.xlabel('q')
plt.ylabel(f'λi')
ax.text(0.15, 0.75, f'$\lambda_{i+1}$ | N={n}', horizontalalignment='center',
verticalalignment='center', transform=ax.transAxes)
# ax.text(0.15, 0.85, f'N=n', horizontalalignment='center',
# verticalalignment='center', transform=ax.transAxes)
qValues_Red = GenerateQs(0, 3, 0.1)
qValues_M = GenerateQs(0, 3, 0.05)
xs_Red = LambdaEvolution(n, i+1, 0, 0.1)
xs_M = LambdaEvolution(n, i+1, 0, 0.05)
if(i+1 == id):
print(f'Solution {id} for N={n}')
print(f'Reduced | N={nqReduced}')
print(qValues_Red)
print(xs_Red)
print(f'Accurate| N={nqM}')
print(qValues_M)
print(xs_M)
f = open(filename, "w")
f.write(str(qValues_M))
f.write('\n')
f.write(str(xs_M))
f.close()
ax.plot(qValues_Red, xs_Red, 'r-o', label=f'nd={nqReduced}')
ax.plot(qValues_M, xs_M, 'b-', label=f'nd={nqM}')
ax.legend(loc='best')
plt.savefig(plotname, bbox_inches='tight')
plt.close()
ShowSolutions(10, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment