【问题标题】:No graph plotted in output using python没有使用python在输出中绘制图表
【发布时间】:2021-07-04 15:55:43
【问题描述】:

我有一个代码,我想使用 vpython 查看输出。 以下是代码

#!/usr/local/bin/ python3
from vpython import *
Plot1 = gcurve ( color = color . white )
for x in arange(0., 8.1, 0.1):
        Plot1.plot( pos = (x, 5.*cos(2.*x)*exp(-0.4*x)) )

graph1 = gdisplay ( width =600, height =450 ,\
        title="Visual 2D Plot", xtitle="x", ytitle="f(x)",\
        foreground = color . black , background = color . white )
Plot2 = gdots ( color = color . black )

for x in arange( -5., +5, 0.1 ):
        Plot2.plot(pos = (x, cos(x)))

它给出了这个错误,但是,它显示了一个白色背景的框,其中没有任何情节。 错误:未定义名称“gdisplay”

如何定义g显示?

【问题讨论】:

    标签: python vpython


    【解决方案1】:

    在 VPython 7 中,名称是“graph”,而不是 gdisplay。并且“from vpython import *”包括图形对象。

    【讨论】:

      【解决方案2】:

      需要导入VPython的可视化模块:

      from visual.graph import *
      

      【讨论】:

      • 它不能从 visual.graph 导入 * ModuleNotFoundError: No module named 'visual'
      • visual 是多年前模块的名称,但现在是 vpython,如前所述,绘图机器现在被命名为“graph”,而不是“gdisplay”。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      • 2021-04-02
      • 2020-03-22
      相关资源
      最近更新 更多