意外所需的参数' bottom'在matplotlib.pyplot.barh()中

时间:2018-06-16 08:16:49

标签: python matplotlib

我正在绘制一个简单的水平条形图。为了便于阅读,我想使用 关键字参数,但是当我这样做时,我得到了一个带有未记录的必需参数的错误。

import pandas as pd
import matplotlib.pyplot as plt
plt.figure(figsize=(4,2))

# this example works
plt.barh([1, 1, 1], 
         [9.5, 8.5, 28.5], 
         [.3, .3, .3],
         [-2207, -2197, -2188])

# here I want to use keyword arguments for readability, according to 
# https://matplotlib.org/api/_as_gen/matplotlib.pyplot.barh.html?highlight=barh  
plt.barh(y=[1, 1, 1], 
         width= [9.5, 8.5, 28.5], 
         height = [.3, .3, .3],
         left = [-2207, -2197, -2188])

# But I get error:
#   File "<ipython-input-6-2f6ee5c89917>", line 4, in <module>
#   left = [-2207, -2197, -2188])

# TypeError: barh() missing 1 required positional argument: 'bottom'

没有&#39;底部&#39; documentation中的参数:

bar(y, width, *, align='center', **kwargs)
bar(y, width, height, *, align='center', **kwargs)
bar(y, width, height, left, *, align='center', **kwargs)```

0 个答案:

没有答案