Skip to content

Commit

Permalink
Add functions to plot and format STM from .dat file
Browse files Browse the repository at this point in the history
  • Loading branch information
wladerer committed Feb 12, 2024
1 parent 89dbdc0 commit 910fc72
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions utils/stm_tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.font_manager as fm

def plot_stm_from_dat(file: str, gridsize: int = 300):
def get_plot_stm_from_dat(file: str, gridsize: int = 300) -> plt:
'''Plots a STM from a .dat file generated by Critic2'''
data = np.loadtxt(file)
plt.hexbin(data[:,2], data[:,3], C=data[:,4], gridsize=gridsize, cmap='Greys_r')
plt.colorbar(label='Relative Height (arb. units)')
plt.show()

return plt

def format_stm_plot(plt: plt, title: str = 'Simulated STM', mode: str = 'current') -> plt:
'''Formats the plot of a STM'''
# Set font to serif
plt.rcParams['font.family'] = 'serif'
# Set title
plt.title(title)
# Replace \AA with angstrom symbol
plt.xlabel(r'x ($\mathrm{\AA}$)')
plt.ylabel(r'y ($\mathrm{\AA}$)')

if mode == 'current':
plt.colorbar(label=r'Tip Height ($\mathrm{\AA}$)')
elif mode == 'height':
plt.colorbar(label='Current (a.u.)')

return plt

def plot_stm_from_dat(file: str, title: str = 'Simulated STM', mode: str = 'current', gridsize: int = 300) -> plt:
'''Plots a STM from a .dat file generated by Critic2'''
plt = get_plot_stm_from_dat(file, gridsize)
plt = format_stm_plot(plt, title, mode)

return plt.show()


0 comments on commit 910fc72

Please sign in to comment.