HP Forums

Full Version: Python: How to Show a Plot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is what I have so far:

Code:
from matplol import *
# scatter plot
axis((0,0,10,10))
grid(True)
plot(1,1)
xlist=[1,2,3,4,5]
ylist=[7,8,9,8,7]
show()

Nothing is shown.

Software Version 5/5/2021 (2.1.14588) - Hardware Version D
(05-09-2021 06:29 PM)Eddie W. Shore Wrote: [ -> ]This is what I have so far:

Code:
from matplol import *
# scatter plot
axis((0,0,10,10))
grid(True)
plot(1,1)
xlist=[1,2,3,4,5]
ylist=[7,8,9,8,7]
show()

Nothing is shown.

Software Version 5/5/2021 (2.1.14588) - Hardware Version D

Hi Eddie, a couple of things:
  • matplotl is misspelled in your code
  • from your code, the only thing I see plotted is a point plot(1,1), are you trying to plot xlist and ylist?
  • it seems grid and axis are not yet working--also, I believe the syntax for axis is axis([0, 10, 0, 10])
Code:

import matplotl import *
import hpprime import *

axis([0,0,10,10])
grid(True)
plot(1,1)
xlist=[1,2,3,4,5]
ylist=[7,8,9,8,7]
scatter(xlist,ylist)
eval("wait()")

Still nothing is showing. I can get plots with graphic module fine though.
(05-09-2021 09:21 PM)Eddie W. Shore Wrote: [ -> ][code]
import matplotl import *
import hpprime import *

...

Should be "from matplotl import *", right?
(05-09-2021 09:21 PM)Eddie W. Shore Wrote: [ -> ]
Code:

import matplotl import *
import hpprime import *
...

Official Python syntax says this should be
Code:

from matplotl import *
from hpprime import *

but yeah, I get nothing displayed either - using the HP Prime Virtual Calculator beta.
(05-09-2021 09:21 PM)Eddie W. Shore Wrote: [ -> ]
Code:

import matplotl import *
import hpprime import *

axis([0,0,10,10])
grid(True)
plot(1,1)
xlist=[1,2,3,4,5]
ylist=[7,8,9,8,7]
scatter(xlist,ylist)
eval("wait()")

Still nothing is showing. I can get plots with graphic module fine though.

The scatter and scatterplot commands do not work for me. The commands plot and hist do.

Below is a code you can try using plot:

Code:

from matplotl import *

xlist=[1,2,3,4,5]
ylist=[7,8,9,8,7]
plot(xlist,ylist)

For reference, I have the HP Prime G2.
I don't have the beta installed so i can't try it, but wouldn't you need something like:

from matplotl import * as plt

and then

plt.grid(True)
plt.plot(xlist,ylist)
...etc?

similar to this:

[attachment=9461]

-road
(05-10-2021 05:50 PM)roadrunner Wrote: [ -> ]I don't have the beta installed so i can't try it, but wouldn't you need something like:

from matplotl import * as plt

and then

plt.grid(True)
plt.plot(xlist,ylist)
...etc?

In Python on other machines, if you leave off the "as plt" clause, you don't need the qualifier plt in front of the function names.
maybe the new firmware needs a good revision. we hope for the future
Reference URL's