Skip to content

Take data directly in Lua #493

@gerion0

Description

@gerion0

I want to draw a box plot with pgfplots and in the documentation is mentioned that calculating the data with Lua is much faster than with TeX. Additionally, my data are already present in form of Lua tables.

My question now is: Is it possible to get the Lua data directly into pgfplots without the indirection over TeX?
I searched online for something similar and only found https://tex.stackexchange.com/questions/676821/pgf-scatterplot-table-from-lua which is more less exactly the way, I don't want to go. The data here is printed with Lua as TeX code, then parsed back into Lua code within pgfplots.

Ideally, I would expect some kind of data specification in pgfplots for Lua data and then be able to provide a global value name of some Lua table that pgfplots then uses as data source.

I mean something like this pseudo code, based on the above example:

\documentclass{article}
\usepackage{luacode}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} 

\begin{luacode*}
userdata = userdata or {}
userdata.pgftable = {
    {}"x", "y", "label"},
    {1, 4.3, "a"},
    {2, 5.1, "a"},
    {3, 5.7, "a"},
    {4, 6.3, "a"},
    {5, 6.8, "a"},
    {6, 7.1, "a"},
    {7, 7.2, "a"},
    {8, 7.2, "a"},
    {9, 7.2, "a"},
    {10, 7.2, "a"},
    {11, 7.5, "a"},
    {12, 7.8, "a"},
}
\end{luacode*}

\begin{document}

\begin{tikzpicture}
\begin{axis}[scatter/classes={a={mark=o, draw=black}}]
\addplot[scatter, only marks, scatter src=explicit symbolic]
    table[meta=label, as_lua=on] {userdata.pgftable};
\end{axis}
\end{tikzpicture}

\end{document}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions