2

I have a code and I want to see output using vpython. following is the code

#!/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)))

it is giving this error, however, it is showing a box of a white background with no plot in it. Error: name 'gdisplay' is not defined

how can I define g display?

ashice
  • 35
  • 6

2 Answers2

1

You need to import the visual module of VPython:

from visual.graph import *
Synthase
  • 5,849
  • 2
  • 12
  • 34
  • it is not working from visual.graph import * ModuleNotFoundError: No module named 'visual' – ashice Apr 08 '21 at 19:22
  • visual was the name of the module many years ago but is now vpython, and as noted here before, the graphing machinery is now named "graph", not "gdisplay". – user1114907 Jul 24 '21 at 04:07
0

With VPython 7 the name is "graph", not gdisplay. And "from vpython import *" includes the graph object.

user1114907
  • 972
  • 8
  • 15