Skip to content

Commit

Permalink
simplify tick generation in PhononBSPlotter._make_ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Dec 15, 2023
1 parent 97cb2ef commit 8952c92
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions pymatgen/phonon/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,24 +274,15 @@ def __init__(self, bs: PhononBandStructureSymmLine, label: str | None = None) ->
def _make_ticks(self, ax: Axes) -> Axes:
"""Utility private method to add ticks to a band structure."""
ticks = self.get_ticks()
# Sanitize only plot the uniq values
uniq_d = []
uniq_l = []
temp_ticks = list(zip(ticks["distance"], ticks["label"]))
for idx, tt in enumerate(temp_ticks):
if idx == 0:
uniq_d.append(tt[0])
uniq_l.append(tt[1])
else:
uniq_d.append(tt[0])
uniq_l.append(tt[1])

ax.set_xticks(uniq_d)
ax.set_xticklabels(uniq_l)
# zip to sanitize, only plot the uniq values
xs, labels = zip(*zip(ticks["distance"], ticks["label"]))
ax.set_xticks(xs)
ax.set_xticklabels(labels)

for idx, label in enumerate(ticks["label"]):
if label is not None:
ax.axvline(ticks["distance"][idx], color="k")
ax.axvline(ticks["distance"][idx], color="black")
return ax

def bs_plot_data(self) -> dict[str, Any]:
Expand Down

0 comments on commit 8952c92

Please sign in to comment.