Maybe I finally see the point of this question. Of course we cannot explain pyplot here, because that is much too complicated and would require a complete tutorial (which btw do exist). But we can have a look at how pyplot would work as a module in a very simplified manner.
So let's create myplot
, the ultimative console plotting library. ;-)
The module myplot could look as follows. It has two functions, scatter
and show
and two variables, figures
and plot
. plot
would store our coordinate system to plot to. figures
would store the figures we create.
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)
Calling scatter
creates a new figure from plot
and stores it in the figures
list. Calling show
takes all figures from that list, and shows them (prints them in the console).
So using myplot
would look exactly like the example above.
import myplot as mlt
mlt.scatter([2,3,4,5,6,8],[2,5,4,4,3,2])
mlt.show()
Creating the output:
^
| *
| **
| *
| * *
|
+----------->
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…