Description
Bug report
Bug summary
In an non-obvious fashion, sometimes bars get wrong width. Specifically, each subsequent bar expands in width versus the prior one. However, it does this for some datasets but not for others, with no pattern obvious to me.
Code for reproduction
Simplified from my actual code, but this demonstrates problem.
print("Matplotlib version:", mpl.__version__)
print("\nWomen:\n", women)
print("\nMen:\n", men)
attr = 'weight'
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
width = 9
ax2.bar(women[attr], women.total, width=0.75*width, alpha=0.15, label="Log Sales (W)")
ax2.bar(men[attr], men.total, width=width, alpha=0.15, label="Log Sales (M)")
ax2.grid(False)
ax2.set_yscale('log')
The datasets are these:
Women:
weight return_rate total
0 90 0.163740 5240
1 100 0.193345 197812
2 110 0.180067 317877
3 120 0.169454 1048820
4 130 0.163293 760693
5 140 0.157449 1294401
6 150 0.154873 604145
7 160 0.149343 800071
8 170 0.147225 319150
9 180 0.146417 465691
10 190 0.146796 165134
11 200 0.150957 195493
Men:
weight return_rate total
12 90 0.135135 37
13 100 0.120954 3522
14 110 0.117764 6547
15 120 0.128846 41833
16 130 0.103845 38750
17 140 0.110603 134761
18 150 0.107671 93628
19 160 0.111633 215824
20 170 0.112077 109800
21 180 0.102720 231551
22 190 0.104230 89821
23 200 0.098818 132213
Actual outcome
Under Matplotlib 3.1.1 I get this distorted effect:
It appears that each subsequent bar is Nx wider. I.e. first bar is fine, next is 2x width, next is 3x width, etc.
Even stranger, the distortion applies only to the "Men" bars. This is true if I change the order they are rendered in, and also is true if I comment out one or the other set of bars. I.e. women are fine, whether displayed solely or in combo; men are broken whether or not the women bars are displayed.
Expected outcome
Under Matplotlib 3.0.3, the output looks as desired. Specifically, the two sets of bars overlay each other with one narrower to aid reading both sets.
Matplotlib version
- Operating system: Linux popbmi 5.0.0-28-generic Overhaul make.osx in master #30-Ubuntu SMP Wed Sep 4 11:47:46 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
- Matplotlib version: 3.1.1
- Matplotlib backend (
print(matplotlib.get_backend())
): module://ipykernel.pylab.backend_inline - Python version: '3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21) \n[GCC 7.3.0]'
- Jupyter version (if applicable): 1.0.0
- Other libraries:
Conda installs.