#heatmap #matplotlib #ramachandran #dihedral
def draw_2DFEL(x, y, bins=40, levels=[0,8]):
H, xedges, yedges = np.histogram2d(x, y, bins=bins)
# Plot the contour lines
fig, ax = plt.subplots()
pmf = -np.log(H.T)
pmf = pmf - np.min(pmf)
levels = np.arange(levels[0], levels[1], 1)
contourf = ax.contourf(pmf, levels=levels, origin='lower', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
ax.scatter(x, y, s=3.0)
cbar = plt.colorbar(contourf, label=r'Free energy / $k_{b}T$')
cbar.ax.yaxis.label.set_fontsize(20)
ax.set_aspect('equal')
ax.set_xlabel(r"$\phi$ [°]", fontsize=20)
ax.set_ylabel(r"$\psi$ [°]", fontsize=20)
#ax.set_title(f"{dihed_pair_dict[i]}\nDir{dir}")
ax.set_xlim(-180, 180)
ax.set_ylim(-180, 180)
plt.tight_layout()
plt.show()