在Ipython中,名为display的函数给了我一个错误 #开普勒定律.py #绘制行星在偏心轨道上的轨道以说明 #以太阳为焦点,在相同的时间内从相同的区域扫出 #轨道的偏心率是随机的,由初始速度决定 #程序使用标准化单位(G=1) 英国伯明翰大学彼得博尔切兹计划 从vpython导入* 从随机导入随机 从IPython导入显示 作为pd进口熊猫 def MonthStep(时间,偏移量=20,整数=1):#标记每个“月”的末尾 全局ccolor#必须使其全局化,因为标签在更新之前使用它 如果完整: Ltext=str(int(time*2+dt))#月底,打印两次时间在“年”中给出大约12个“月” 其他: Ltext=持续时间+str(时间*2)+“月”\n初始速度:'+str(轮速,3)) ccolor=color.white 标签(pos=planet.pos,text=Ltext,color=ccolor, xoffset=偏移*行星位置x,yoffset=偏移*行星位置y) ccolor=(0.5*(1+random()),random(),random())#径向向量的随机颜色 返回彩色 场景=显示(title=“开普勒等面积定律”,宽度=1000,高度=1000,范围=3.2) 持续时间='期间:' 太阳=球体(颜色=颜色.黄色,半径=0.1)#忽略太阳的运动(或质心坐标) 比例=1.0 poss=向量(0,比例,0) 行星=球体(pos=poss,color=color.cyan,半径=0.02) 而1: 速度=-矢量(0.7+0.5*random(),0,0)#给出了令人满意的偏心范围 ##速度=-向量(0.984,0,0)#给出12.0“月”的周期 速度=mag(速度) 步骤=20 dt=0.5/浮点数(步数) 步长=0 时间=0 ccolor=color.white oldpos=矢量(行星位置) ccolor=月步(时间) 曲线(位置=[sun.pos,planet.pos],颜色=ccolor) 而不是(旧位置x>0且行星位置x

在Ipython中,名为display的函数给了我一个错误 #开普勒定律.py #绘制行星在偏心轨道上的轨道以说明 #以太阳为焦点,在相同的时间内从相同的区域扫出 #轨道的偏心率是随机的,由初始速度决定 #程序使用标准化单位(G=1) 英国伯明翰大学彼得博尔切兹计划 从vpython导入* 从随机导入随机 从IPython导入显示 作为pd进口熊猫 def MonthStep(时间,偏移量=20,整数=1):#标记每个“月”的末尾 全局ccolor#必须使其全局化,因为标签在更新之前使用它 如果完整: Ltext=str(int(time*2+dt))#月底,打印两次时间在“年”中给出大约12个“月” 其他: Ltext=持续时间+str(时间*2)+“月”\n初始速度:'+str(轮速,3)) ccolor=color.white 标签(pos=planet.pos,text=Ltext,color=ccolor, xoffset=偏移*行星位置x,yoffset=偏移*行星位置y) ccolor=(0.5*(1+random()),random(),random())#径向向量的随机颜色 返回彩色 场景=显示(title=“开普勒等面积定律”,宽度=1000,高度=1000,范围=3.2) 持续时间='期间:' 太阳=球体(颜色=颜色.黄色,半径=0.1)#忽略太阳的运动(或质心坐标) 比例=1.0 poss=向量(0,比例,0) 行星=球体(pos=poss,color=color.cyan,半径=0.02) 而1: 速度=-矢量(0.7+0.5*random(),0,0)#给出了令人满意的偏心范围 ##速度=-向量(0.984,0,0)#给出12.0“月”的周期 速度=mag(速度) 步骤=20 dt=0.5/浮点数(步数) 步长=0 时间=0 ccolor=color.white oldpos=矢量(行星位置) ccolor=月步(时间) 曲线(位置=[sun.pos,planet.pos],颜色=ccolor) 而不是(旧位置x>0且行星位置x,ipython,vpython,glowscript,Ipython,Vpython,Glowscript,我在谷歌上复制了开普勒定律代码,并在pycharm上编译 但有一个错误是 场景=显示(title=“开普勒等面积定律”,宽度=1000,高度=1000,范围=3.2) TypeError:“模块”对象不可调用 我在谷歌上发现了一些信息,“熊猫”库可以改善这个错误,所以我尝试了一下,但我无法改善这个错误 我该怎么办?将“显示”替换为“画布”,这是该实体的正确名称 # Kepler's Laws.py # plots the orbit of a planet in an eccentric or

我在谷歌上复制了开普勒定律代码,并在pycharm上编译

但有一个错误是

场景=显示(title=“开普勒等面积定律”,宽度=1000,高度=1000,范围=3.2)

TypeError:“模块”对象不可调用

我在谷歌上发现了一些信息,“熊猫”库可以改善这个错误,所以我尝试了一下,但我无法改善这个错误

我该怎么办?

将“显示”替换为“画布”,这是该实体的正确名称

# Kepler's Laws.py

# plots the orbit of a planet in an eccentric orbit to illustrate
# the sweeping out of equal areas in equal times, with sun at focus
# The eccentricity of the orbit is random and determined by the initial velocity
# program uses normalised units (G =1)

# program by Peter Borcherds, University of Birmingham, England

from vpython import *
from random import random
from IPython import display
import pandas as pd

def MonthStep(time, offset=20, whole=1):  # mark the end of each "month"
    global ccolor  # have to make it global, since label uses it before it is updated
    if whole:
        Ltext = str(int(time * 2 + dt))  # end of 'month', printing twice time gives about 12 'months' in 'year'
    else:
        Ltext = duration + str(time * 2) + ' "months"\n Initial speed: ' + str(round(speed, 3))
        ccolor = color.white
    label(pos=planet.pos, text=Ltext, color=ccolor,
          xoffset=offset * planet.pos.x, yoffset=offset * planet.pos.y)
    ccolor = (0.5 * (1 + random()), random(), random())  # randomise colour of radial vector
    return ccolor


scene = display(title="Kepler's law of equal areas", width=1000, height=1000, range=3.2)
duration = 'Period: '
sun = sphere(color=color.yellow, radius=0.1)  # motion of sun is ignored (or centre of mass coordinates)
scale = 1.0
poss = vector(0, scale, 0)
planet = sphere(pos=poss, color=color.cyan, radius=0.02)

while 1:
    velocity = -vector(0.7 + 0.5 * random(), 0, 0)  # gives a satisfactory range of eccentricities
    ##velocity = -vector(0.984,0,0)   # gives period of 12.0 "months"
    speed = mag(velocity)
    steps = 20
    dt = 0.5 / float(steps)
    step = 0
    time = 0
    ccolor = color.white
    oldpos = vector(planet.pos)
    ccolor = MonthStep(time)
    curve(pos=[sun.pos, planet.pos], color=ccolor)

    while not (oldpos.x > 0 and planet.pos.x < 0):

        rate(steps * 2)  # keep rate down so that development of orbit can be followed
        time += dt
        oldpos = vector(planet.pos)  # construction vector(planet.pos) makes oldpos a varible in its own right
        # oldpos = planet.pos makes "oldposs" point to "planet.pos"
        # oldposs = planet.pos[:] does not work, because vector does not permit slicing
        denom = mag(planet.pos) ** 3
        velocity -= planet.pos * dt / denom  # inverse square law; force points toward sun
        planet.pos += velocity * dt

        # plot orbit
        curve(pos=[oldpos, planet.pos], color=color.red)

        step += 1
        if step == steps:
            step = 0
            ccolor = MonthStep(time)
            curve(pos=[sun.pos, planet.pos], color=color.white)
        else:
            # plot radius vector
            curve(pos=[sun.pos, planet.pos], color=ccolor)

        if scene.kb.keys:
            print
            "key pressed"
            duration = 'Duration: '
            break

    MonthStep(time, 50, 0)
    label(pos=(2.5, -2.5, 0), text='Click for another orbit')
    scene.mouse.getclick()
    for obj in scene.objects:
        if obj is sun or obj is planet: continue
        obj.visible = 0  # clear the screen to do it again