barh() missing 1 required positional argument: 'y
时间: 2023-11-09 11:07:12 浏览: 95
这个报错是因为在使用`barh()`函数时缺少了一个必需的参数 `y`。根据引用中的示例代码,`barh()`函数需要传入两个参数,分别是`y`和`width`。其中,`y`参数表示条形图的纵坐标,而`width`参数表示条形图的宽度。你需要确保在使用`barh()`函数时同时传入这两个参数,以解决这个报错。
相关问题
TypeError: barh() got multiple values for argument 'width'
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`).
matlab barh
matlab中的barh函数是用来绘制水平条形图的,其中h表示horizontal。它可以用来展示不同类别之间的数量或比较不同类别的大小。函数的语法如下:
barh(y) % y为一个向量,表示每个条形的高度
barh(x,y) % x为一个向量,表示每个条形的位置;y为一个向量,表示每个条形的高度
barh(...,'PropertyName',PropertyValue,...) % 可以设置一些属性,如颜色、标签等
例如,我们可以使用以下代码绘制一个简单的水平条形图:
```matlab
y = [5 8 4 2 7];
barh(y)
```
这将绘制出五个条形,每个条形的高度分别为5、8、4、2和7。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)