如何使用Zelle图形绘制绘图? [英] How to undraw plot with Zelle graphics?

查看:160
本文介绍了如何使用Zelle图形绘制绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是使用John Zelle的 graphics.py 的Python 3.5.2的代码问题:



我有花了很多时间在这里寻找答案,但无法弄清楚。函数 undraw()的存在与 getMouse()一样。但似乎它对 plot()命令不起作用,仅对 draw()命令起作用。我究竟做错了什么?以及如何使窗口保持打开状态,但在绘制下一个图之前删除前一个图?



pdf文档中的 graphics功能



     http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

  win = GraphWin( Plot,500,500)#为范围(0,j)中的m创建一个窗口

:#每个函数的循环
#为每个函数随机化一种颜色
color = random.choice(['red','black','green','yellow','pink','blue'])
for h在range(0,t)中:#为每对值 x,y循环
#查找点并在win中绘制每个点
win.plot(axis [h],points [m] [h],彩色)
win.getMouse()#单击
前暂停。win.undraw()#AttributeError:'GraphWin'对象没有属性'undraw'


解决方案

第一个问题是 undraw() GraphicsObject 的方法,而不是 GraphWin ,所以 win.undraw()就是不正确的。



第二个问题是 plot()是一种低级像素设置方法,与绘制的对象不同,它无法在Zelle Graphics级别跟踪其操作。 p>

但是,支撑点是Tkinter,它确实跟踪绘制的对象,而GraphWin是Canvas的子类,因此您可以执行以下操作:

  win = GraphWin( Plot,500,500)#为范围内的m(j)创建一个窗口

:#循环对于每个函数
color = random.choice(['red','black','green','yellow','pink','blue'])#为每个函数
随机分配颜色对于h在range(t)中:#为每对值 x,y循环
win.plot(axis [h],points [m] [h],color)#查找点并绘制每个点in win
win.getMouse()#在单击
之前暂停win.delete( all)#清除旧图


This is a code problem for Python 3.5.2 using John Zelle's graphics.py:

I have spent a good amount of time looking for the answer here, but just can not figure it out. The function undraw() exists just like getMouse(). But it seems like it do not work for the plot() command, only the draw() command. What am I doing wrong? And how can I keep the window open, but erase the previous the plot before the next one is drawn?

pdf documentation for the functions of graphics:

    http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

win = GraphWin("Plot",500,500) # Creates a window

for m in range(0,j): # Loop for each function
    # Randomizes a color for each function
    color = random.choice( ['red','black','green','yellow','pink','blue'] )
    for h in range(0,t): # Loop for each pair of values "x,y"
        # Find points and plot each point in win
        win.plot(axis[h],points[m][h],color)
    win.getMouse() # Pause before clicking
    win.undraw() # AttributeError: 'GraphWin' object has no attribute 'undraw'

解决方案

The first issue is that undraw() is a method of GraphicsObject, not GraphWin, so win.undraw() is simply incorrect.

The second issue is that plot() is a low level pixel setting method that does not keep track of what it did at the Zelle Graphics level, unlike objects that are drawn.

However, the underpinning is Tkinter which does keep track of objects that it draws, and GraphWin is a subclass of Canvas, so you can do:

win = GraphWin("Plot", 500, 500) # Creates a window

for m in range(j):  # Loop for each function
    color = random.choice(['red', 'black', 'green', 'yellow', 'pink', 'blue']) # Randomizes a color for each function
    for h in range(t):  # Loop for each pair of values "x, y"
        win.plot(axis[h], points[m][h], color) # Find points and plot each point in win
    win.getMouse()  # Pause before clicking
    win.delete("all")  # Clear out old plot

这篇关于如何使用Zelle图形绘制绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆