plt.figure(12,8)报错from_bounds() argument after * must be an iterable, not int
时间: 2023-06-23 07:09:12 浏览: 301
这个错误通常是因为 `plt.figure()` 函数的第一个参数需要传入一个元组或列表,而不是一个整数。请修改代码,将第一个参数修改为一个元组或列表,例如:
```python
plt.figure(figsize=(12, 8))
```
这将创建一个大小为 12x8 的图形对象。如果你想设置图形对象的编号,可以在 `plt.figure()` 函数的第二个参数中传入一个整数,例如:
```python
plt.figure(figsize=(12, 8), num=1)
```
这将创建一个大小为 12x8,编号为 1 的图形对象。
相关问题
TypeError: matplotlib.transforms.Bbox.from_bounds() argument after * must be an iterable, not int
这个错误通常是因为在调用`matplotlib.transforms.Bbox.from_bounds()`函数时,传递的参数不正确导致的。这个函数的参数需要传入4个浮点数,分别表示一个矩形的左下角和右上角的坐标。
例如,下面的代码就会出现这个错误:
```python
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
fig, ax = plt.subplots()
bbox = Bbox.from_bounds(0, 0, 100, 100)
```
上面的代码中,我们调用`Bbox.from_bounds()`函数时,传递的参数分别是0、0、100和100,这是4个整数,而函数要求的是4个浮点数。
为了解决这个问题,我们需要将传递的参数改为浮点数:
```python
import matplotlib.pyplot as plt
from matplotlib.transforms import Bbox
fig, ax = plt.subplots()
bbox = Bbox.from_bounds(0.0, 0.0, 100.0, 100.0)
```
上面的代码中,我们将传递的参数改为了浮点数,这样就不会再出现上述错误了。
需要注意的是,在使用`Bbox.from_bounds()`函数时,参数的顺序应该是左、下、右、上,即先是左下角的坐标,再是右上角的坐标。
plt.figure() plt.plot(x11, x11_2) plt.plot(x32, x32_2) plt.figure() plt.plot(m11, m11_2) plt.plot(m32, m32_2) plt.show() 设置不要刻度和图四周的留白
要设置不要刻度和图四周的留白,可以使用以下代码:
```python
import matplotlib.pyplot as plt
# 创建第一个图
plt.figure()
plt.plot(x11, x11_2)
plt.plot(x32, x32_2)
plt.axis('off') # 关闭刻度
plt.margins(0) # 去除四周留白
# 创建第二个图
plt.figure()
plt.plot(m11, m11_2)
plt.plot(m32, m32_2)
plt.axis('off') # 关闭刻度
plt.margins(0) # 去除四周留白
# 显示图形
plt.show()
```
在每个 `plt.figure()` 后面加入 `plt.axis('off')` 可以关闭刻度,加入 `plt.margins(0)` 可以去除四周的留白。最后使用 `plt.show()` 显示图形。