cancel
Showing results for 
Search instead for 
Did you mean: 

EmbedPy question, function in python that returns more than one value.

krish240574
New Contributor

Python code :  fig, axes = plt.subplots(ncols=2, figsize=(24, 8), dpi=100)

q code :

plt:.p.import[`matplotlib;`:pyplot]
plt[`:subplots;<;pykwargs `ncols`figsize`dpi!(2;24 8;100)] returns (foreign;foreign) - corresponding to (fig, axes) in python. How do I access each value of the returned list of (foreign;foreign), inside q?

Thanks,

Kumar

2 REPLIES 2

sstantoncook
New Contributor II
New Contributor II

Hi Kumar,

To index into a python objext you can use the syntax of a backtick character "`" to convert to q. E.g.
variable`

If you have a list of variable you want to index into you could alternatively write

{x ` } each list_of_python_variables

or
list_of_python_variables@\:` 

Depending on which syntax you prefer.

Cheers,

Sam

rocuinneagain
New Contributor III
New Contributor III

You can use .p.wrap https://code.kx.com/q/ml/embedpy/userguide/#embedpy-objects_1

 

Small example giving each subplot a title:

plt:.p.import[`matplotlib;`:pyplot]
plts:plt[`:subplots;<;pykwargs `ncols`figsize`dpi!(2;24 8;100)]
.p.wrap[plts[1;0]][`:set_title]"Plot1";
.p.wrap[plts[1;1]][`:set_title]"Plot2";
plt[`:show][];

Results in:

rocuinneagain_0-1628861965654.png