+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Python Matplotl usage (/thread-18992.html)
I have upgraded my HP Prime firmware & got python. I tried running stuff & its works. But I cannot display plot. Steps while in Python Numeric View (Apps)
Code:
from math import *
from matplotl import *
uk_x= [0.1*i for i in range(-10,10)]
uk_x #displays correct list of values
uk_y= [cos(i) for i in uk_x]
uk_y #displays correct list of values
plot(uk_x,uk_y) # no error but nothing happens as well
plot.show() #nothing
show() #nothing
Now If i want to assign values (list) stored in uk_x & uk_y to native HP Prime list variables say L1 & L2 how should I proceed? These then can be used in Stats APP for plotting & further stuff
The sad reality is that the PYTHON implementation on the Prime is extremely incomplete and buggy, read unreliable. To my knowledge there is no list at all of functions that are implemented. Therefore it's almost impossible to determine whether you made an error in your code or the function you try to use simply doesn't do anything.
There is no help available. I've really done a lot of investigation, but finally I almost gave up.
Sorry, Günter
RE: Python Matplotl usage - Eddie W. Shore - 10-24-202202:01 AM
I agree, Guenter. I think the documentation needs to be more complete.
mathplotl is one of the MicroPython modules I wrote for Numworks/Casio/TI Nspire CX and was ported by Cyrille to the Prime. Unfortunately the port was done very fast, and there a few bugs remaining, like the show() problem.
As for help, there is online help for many instructions if you press the Help key from the Commands menu from Python shell. matplotl commands were added last, and do not have online help. They emulate the simplest commands of the Python matplotl commands : a matplot command is translated to an Xcas equivalent. Then show() is supposed to display the collection of Xcas geometric objects but as far as I remember, there is no wait instruction and the display is overwritten. I would therefore suggest to try the following workaround: add after matplotl.show() a prime.eval instruction with a WAIT instruction inside. If that does not work I'm afraid you're stuck until a new firmware is published.
The source code of the GPL version (with a few fixes with respect to HP version) that runs inside Xcas follows.
Code:
/* MATPLOTL */
static mp_obj_t matplotl_show(size_t n_args, const mp_obj_t *args) { // Prime source code is different
const char * val=caseval("show()");
return mp_obj_new_str(val,strlen(val));
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(matplotl_show_obj, 0, 0, matplotl_show);
Quote:add after matplotl.show() a prime.eval instruction with a WAIT
It seems working but the result is attached The axis & all other stuff is missing through I invoked them in code explicitly
I think some code from graphics() library is to be used which I don't know
Code:
EXPORT ukchart()
BEGIN
PYTHON(ukchart0);
WAIT(0);
END;
#PYTHON ukchart0()
from matplotl import *
from linalg import *
from math import *
x=linspace(0,90,100)
y=[cos(j) for j in x]
clf()
plot(x,y)
axis(0,90,-1,1) #also tried axis('on') | axis('square')
show()
#end
RE: Python Matplotl usage - parisse - 10-25-202210:04 AM
On your screenshot it seems the screen is not cleared, you might try any other Python clearing screen instruction, but no warranty...
Some Xcas commands called from matplotl are currently missing (means hidden) on the Prime. For example, if you look at the clf code, it calls erase() but erase is not available on the Prime.
EXPORT ukchart()
BEGIN
PYTHON(ukchart0);
WAIT(0);
END;
It did reduce line clutter but axis aren't available nor the background is solid
I suggest you to add an HPPL clearing screen instruction before calling your python code.
Axes can not work since it is translated to axes, and the keyword axes is not exposed in the HP CAS parser. That's a good observation, I must add some keywords in the HP Prime CAS parser/lexer if we want to have matplotl working some day in the future on the Prime (like on other KhiCAS platforms)