python - 为什么 matplotlib 中显示两条线?

标签 python matplotlib graphing

我不明白为什么 matplotlib 要创建另一行?

import matplotlib.pyplot as plt

xy1 = []
x1 = 0


while x1 < 10:
    x1 = x1 + 1
    y1 = x1**2 
    xy1.append([x1,y1])


plt.plot(xy1)
print(xy1)
plt.show()

enter image description here

最佳答案

来自documentation ,您可以看到 plt.plot 可以绘制多个图:

If x and/or y is 2-dimensional, then the corresponding columns will be plotted.

您的数据如下所示:

[[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

关于python - 为什么 matplotlib 中显示两条线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272825/

相关文章:

ruby-on-rails - 使用 Seer 在 Rails 应用程序中按日期绘制新用户图

python - 读取和绘制从大文件中读取的数据

android - 适用于 Android 的 GPL 兼容图形库

python - 使用 PyInstaller 仅将 Python 字符串转换为 float 失败

python - App Engine、appcfg 和保存上传凭据

python - plt.show 和 cv2.imshow 的区别?

python - 我的时间序列图显示了错误的顺序

从完整文件路径中提取文件名及其父目录的Pythonic方法?

python - 在 PyGame、Python 3 上演奏和弦

具有堆叠数据的 Python Pandas 子图