TypeError: barh() got multiple values for argument 'width'
时间: 2024-05-03 12:22:37 浏览: 513
This error occurs when the `barh()` function in Matplotlib is called with more than one argument for the `width` parameter. The `width` parameter specifies the width of the bars in a horizontal bar chart.
Here's an example of how this error can occur:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.barh(x, y, width=0.5, width=0.3)
```
In this example, the `barh()` function is called with two values for the `width` parameter (`0.5` and `0.3`). This causes the `TypeError` to be raised.
To fix this error, simply remove the extra argument for the `width` parameter:
```python
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.barh(x, y, width=0.5)
```
In this fixed example, the `barh()` function is called with only one value for the `width` parameter (`0.5`).
阅读全文