From 8952c923ab95c11ba1871f13129fa466a41a6590 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 14 Dec 2023 16:17:49 -0800 Subject: [PATCH] simplify tick generation in PhononBSPlotter._make_ticks --- pymatgen/phonon/plotter.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/pymatgen/phonon/plotter.py b/pymatgen/phonon/plotter.py index a89972fd24c..a99f33e1e3b 100644 --- a/pymatgen/phonon/plotter.py +++ b/pymatgen/phonon/plotter.py @@ -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]: