Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
Description
Bug summary
When there are duplicate labels in my label array (for example:['first label', 'second label’, ‘third label', 'second label']
),ax.bar()
andax.barh()
ignore the duplicates (both bars and labels).
Code for reproduction
importmatplotlib.pyplotaspltname= ["first label","second label","third label","second label",]value= [1,2,3,4]fig,ax=plt.subplots(layout="tight")ax.barh(name,value)foriinrange(len(name)):n=name[i]v=value[i]ax.text(x=v+1,y=i,s=f"{n} ({i})",va="center")
Actual outcome
Expected outcome
A bar chart with 4 bars (the second ‘second label’ would be above the bar of the ‘third label’).
What's more, for some reason the bar on the ‘second label’ has a value of 4, whereas I was intuitively expecting it to have a value of 2?
Additional information
You might expect there to be only single labels, but as this isn't explained in the documentation, I've pointed it out just in case. It's quite hard to spot when you're drawing a lot of bars.
Operating system
MacOS Sonoma
Matplotlib Version
3.10.0
Matplotlib Backend
module://positron_ipykernel.matplotlib_backend
Python version
3.13.1
Jupyter version
/
Installation
pip