KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ EmbedPy question, function in python that returns more than one value.

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

    Posted by krish240574 on August 11, 2021 at 12:00 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

    krish240574 replied 9 months ago 4 Members · 3 Replies
  • 3 Replies
  • sstantoncook

    Member
    August 13, 2021 at 12:00 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

  • rocuinneagain

    Member
    August 13, 2021 at 12:00 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:

     

     

  • CareyT

    Administrator
    March 4, 2024 at 10:06 am
    hello

Log in to reply.