2021.08.11 08:11 AM - edited 2021.08.11 08:39 AM
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
2021.08.13 01:21 AM
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
2021.08.13 06:40 AM
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:
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.