FIX: use requested style for empty bar charts. by vossvayne · Pull Request #31973 · matplotlib/matplotlib · GitHub
Skip to content

FIX: use requested style for empty bar charts.#31973

Open
vossvayne wants to merge 1 commit into
matplotlib:mainfrom
vossvayne:issue-21506
Open

FIX: use requested style for empty bar charts.#31973
vossvayne wants to merge 1 commit into
matplotlib:mainfrom
vossvayne:issue-21506

Conversation

@vossvayne

Copy link
Copy Markdown

PR summary

Issue: Bar has no child patches when input data is empty, this leads to the legend handle being left at default as there are no children.

Fix: Store the style information as a fallback and use it when there are no children. This closes #21506.

Example:

import matplotlib.pyplot as plt

ax = plt.figure().add_subplot()
ax.bar([], [], color="red", alpha=0.3, label="empty")
handler = ax.legend().legend_handles[0]
print(handler.get_facecolor()) # (1.0, 0.0, 0.0, 0.3)
print(handler.get_alpha()) # 0.3

AI Disclosure

Fixed manually.

PR checklist

@github-actions

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: plt.bar legend displays incorrect style for empty data

1 participant