也许我终于明白了这个问题的重点。当然我们不能在这里解释pyplot,因为那太复杂了,需要一个完整的教程(确实存在)。但是我们可以看看pyplot如何以非常简化的方式作为模块工作。
因此,让我们创建
myplot最终的控制台绘图库。;-)
myplot模块可能如下所示。它具有两个函数,
scatter以及
show和两个变量,
figures和
plot。
plot将存储我们要绘制的坐标系。
figures将存储我们创建的数字。
plot = """^ | | | | | +----------->"""figures = []def scatter(X,Y): thisplot = list(plot[:]) for x,y in zip(X,Y): thisplot[1+14*(6-y)+x] = "*" thisplot = "".join(thisplot) figures.append(thisplot)def show(): for fig in figures: print(fig)
调用
scatter从中创建一个新图形
plot并将其存储在
figures列表中。调用
show从该列表中取出所有图形,并显示它们(在控制台中打印出来)。
因此,使用
myplot将与上面的示例完全一样。
import myplot as mltmlt.scatter([2,3,4,5,6,8],[2,5,4,4,3,2])mlt.show()
创建输出:
^ | * | ** | * | * * | +----------->



