Skip to content

Commit

Permalink
only show legend in PhononDosPlotter if there are non-empty labels
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Dec 15, 2023
1 parent d5d750f commit 11714b9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pymatgen/phonon/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ def get_plot(
ax.set_xlabel(rf"$\mathrm{{Frequencies\ ({unit.label})}}$", fontsize=legend.get("fontsize", 30))
ax.set_ylabel(r"$\mathrm{Density\ of\ states}$", fontsize=legend.get("fontsize", 30))

ax.legend(**legend)
legend_text = ax.get_legend().get_texts() # all the text.Text instance in the legend
plt.setp(legend_text)
plt.tight_layout()
# only show legend if there are labels
if sum(map(len, keys)) > 0:
ax.legend(**legend)

return ax

def save_plot(
Expand Down

0 comments on commit 11714b9

Please sign in to comment.