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?

2 Answers 2

1

You need to import the visual module of VPython:

from visual.graph import *
Sign up to request clarification or add additional context in comments.

2 Comments

it is not working from visual.graph import * ModuleNotFoundError: No module named 'visual'
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".
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.