Created
May 31, 2022 12:15
-
-
Save fanurs/c970636a1ff9db35dd3fdf1ef177861a to your computer and use it in GitHub Desktop.
Matplotlib legend: Remove error bars, show only marker symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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