Skip to content

Instantly share code, notes, and snippets.

@fanurs
Created May 31, 2022 12:15
Show Gist options
  • Save fanurs/c970636a1ff9db35dd3fdf1ef177861a to your computer and use it in GitHub Desktop.
Save fanurs/c970636a1ff9db35dd3fdf1ef177861a to your computer and use it in GitHub Desktop.
Matplotlib legend: Remove error bars, show only marker symbols
import matplotlib as mpl
import matplotlib.pyplot as plt
# some pseudo-data (incomplete)
df1 = ...
df2 = ...
fig, ax = plt.subplots()
ax.errorbar(df1.x, df1.y, yerr=df1.yerr, label='df1')
ax.errorbar(df2.x, df2.y, yerr=df2.yerr, label='df2')
handles, labels = ax.get_legend_handles_labels()
handles = [h[0] if isinstance(h, mpl.container.ErrorbarContainer) else h for h in handles]
ax.legend(handles, labels)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment