Skip to content

Instantly share code, notes, and snippets.

@physicshinzui
Last active March 7, 2024 11:52
Show Gist options
  • Save physicshinzui/8db6672ebaeed7b320c6ffb2c2668de6 to your computer and use it in GitHub Desktop.
Save physicshinzui/8db6672ebaeed7b320c6ffb2c2668de6 to your computer and use it in GitHub Desktop.
2次元heatmapのpython関数.md

#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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment