首页 > 解决方案 > 如何绘制用户界面

问题描述

注意:这是我的代码的样子,我不断收到粗体部分的错误,我希望能够绘制一条直线,其坐标从 1,1 开始,到 (1+lineLength), 1 结束,这样我就有了一条水平线。我对python不太熟悉,所以我非常感谢您的意见。

lineLengthQuestion = input("What size would you like your line? (Numbers Only)")
lineLengthQuestion = int(lineLengthQuestion)
lineLength = [1 + lineLengthQuestion]
print (f'You entered {lineLengthQuestion}')

x = [1,1]
y = [lineLength, 1]
plt.plot(x, y, color = "black", linewidth = 3)

标签: pythonmatplotlibjupyter-notebookjupytermatplotlib-animation

解决方案


您创建了一个单元素列表,其中包含一个比 大 1 的数字lineLengthQuestion。我认为你想要一个标量值,所以你不需要括号。

lineLength = 1 + lineLengthQuestion

推荐阅读