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

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

q code :

plt:.p.import[matplotlib;:pyplot]
plt[:subplots;\<;pykwargs ncolsfigsizedpi!(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

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

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: