【发布时间】:2022-01-05 17:24:29
【问题描述】:
我正在尝试在 Python 中创建一个图来说明我的序列如何随着n 的增长而变化。我收到尺寸错误。我该如何解决这个问题?
我的代码:
import matplotlib.pyplot as plt
import numpy as np
x = np.zeros(101)
x[0] = 0
for n in range(0, 101):
x[n] = x[n-1] - n
if x[n] < 0:
x[n] = x[n-1] + n
y = set(x)
print(y)
i = np.linspace(0, 100)
plt.plot(y, i, 'g')
错误:
ValueError: x and y must have same first dimension, but have shapes (1,) and (50,)
【问题讨论】:
标签: matplotlib graph error-handling