ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: DesdeChaves <desdechaves@gmail.com>
To: hajtmar@gyza.cz, mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Pgfplots - passing point coordinates by Lua
Date: Sun, 16 Feb 2014 23:53:51 +0000	[thread overview]
Message-ID: <CAPBmU9FPSk65u2P58vZ300WbRM6KQpmn89+uuzMd1po94BQmnA@mail.gmail.com> (raw)
In-Reply-To: <530142F0.5040703@gyza.cz>


[-- Attachment #1.1: Type: text/plain, Size: 7256 bytes --]

Try this way:

\usemodule[tikz]
\usemodule[pgfplots]
\usemodule[pgfplotstable]

\starttext

\startluacode

local dados={};

for i=1,10 do
dados[i]=2*i
end

context("\\starttikzpicture")
    context("\\pgfplotsset{width=10cm, compat=1.3, legend
style={font=\\tfx}}")
    context("\\startaxis[")
    context("xlabel={L  (m) },")
    context("ylabel={ $T^2 (s^2)$},legend cell align=left, legend pos=north
west]")
    context("\\addplot[only marks] table[row sep=\\\\]{")
     context("X Y\\\\")
for key,value in pairs(dados) do
context("%0.2f %0.1f \\\\", key, value)
end
 context("   };")
    context("\\addlegendentry{Experimental points}")
    context("\\addplot table[row sep=\\\\,")
    context("y={create col/linear regression={y=Y}}]{")
    context("X Y\\\\")
for key,value in pairs(dados) do
context("%0.2f %0.1f \\\\", key, value)
end
    context("};")
    context("\\addlegendentry{")
        context("$\\pgfmathprintnumber{\\pgfplotstableregressiona} \\cdot
x")
        context("\\pgfmathprintnumber[print
sign]{\\pgfplotstableregressionb}$ lin. Regression}")
    context("\\stopaxis")
context("\\stoptikzpicture")

\stopluacode


\stoptext


Jorge



2014-02-16 23:00 GMT+00:00 Jaroslav Hajtmar <hajtmar@gyza.cz>:

> Hi Lukas.
> A year ago, I tried something similar when I wanted to make an animated
> pdf images.
> With using Lua, I can not handle eventually, but for inspiration attach a
> piece of code that demonstrates how get into buffer some parameters without
> Lua code. Maybe it inspires you in your solution.
>
> I apologize for dirty code, but I cutting it from my old library and my
> context application. I did not clean it and I did not translate into
> English. For those interested I can possibly do.
>
> Jarda Hajtmar
>
> Here is my example:
>
>
> \usemodule[tikz]
> \usemodule[pgfplots]
>
> %\define[1]\ListEntry{#1\par}
> %\processcommalist[one,two,{three,four}]\ListEntry
> %\processseparatedlist[one*two*three,four][*]\ListEntry
> \def\zpracujparametry[#1]#2%
> {\processcommalist[#1]{\nastavparametr{#2}}}
> % Použití:
> % \zpracujparametry[1,5,3.7,4,5,8,9,11]{
> % \getbuffer[funkce1]
> % \page
> % }
>
>
> \def\ZPRACUJPARAMETRY#1[#2]#3%
> {\processseparatedlist[#2][#1]{\nastavparametr{#3}}}
> % Použití:
> % \ZPRACUJPARAMETRY{znak separátoru}[1,5,3.7,4,5,8,9,11]{
> % \getbuffer[funkce1]
> % \page
> % }
>
>
> \def\pmparametr#1=$#2${\global\def\parametr{#1}\global\def\mparametr{#2}}
>
> \def\nastavparametry#1#2{\pmparametr#2\global\def\pparametr{#2}#1}%
>
> \def\zpracujdvojparametry[#1]#2%
> {\processcommalist[#1]{\nastavparametry{#2}}}
> % Použití:
> % \zpracujdvojparametry[1=$a$,5=$b$,3.7=$c$,4=$d$,5=$e$,8=$f$,
> 9=$g$,11=$h$]{
> % \getbuffer[funkce1]
> % \page
> % }
>
> \def\ZPRACUJDVOJPARAMETRY#1[#2]#3%
> {\processseparatedlist[#2][#1]{\nastavparametry{#3}}}
> % Použití:
> % \ZPRACUJDVOJPARAMETRY{;}[1=$a$;5=$b$;3.7=$c$;4=$d$;5=$e$;8=$
> f$;9=$g$;11=$h$]{
> % \getbuffer[funkce1]
> % \page
> % }
>
>
>
> \startbuffer[goniometrickefunkce]
> \def\function{cos(deg(\x+\parametr))}
> \def\permfunction{cos(deg(\x))}
> \def\permfunctiontwo{sin(deg(\x))}
> \startTEXpage
> \starttikzpicture[scale=1]
> \tikzset{style={font=\ssxx}}
> \startaxis
> [xmin=-1.6,
> xmax=10,
> domain=-1.6:10,
> ymin=-1.1,
> ymax=1.1,
> width=\textwidth,
> height=0.3\textwidth,
> axis x line=middle,
> axis y line=middle,
> axis equal=true,
> xlabel=$x$,
> ylabel=$y$,
> samples=600,
> clip=true,
> xtick={0},
> ytick={-1,0,1},
> grid=major,
> extra x ticks={-1.57,1.57,3.14,4.71,6.28,7.85,9.42,10.99,12.57}, extra x
> tick labels={$-\frac{\pi}{2}$,$\frac{\pi}{2}$,$\pi$,$3\!\frac{
> \pi}{2}$,$2\pi$,$5\!\frac{\pi}{2}$,$3\pi$},
> title={{\framed[frame=off,height=1cm]{\blue $\ssb f\!:\ y=\cos{(x
> \mparametr )}$}}},
> ]
>
> \addplot[color=yellow, line width=0.5pt] {\permfunctiontwo};
> \addplot[color=red, line width=0.5pt] {\permfunction};
> \addplot[color=blue, line width=1pt] {\function};
>
> \stopaxis
> \stoptikzpicture
> \stopTEXpage
> \stopbuffer
>
>
>
>
>
>
>
>
>
> \starttext
>
> \ZPRACUJDVOJPARAMETRY{*}[1.57=$+\frac{\pi}{2}$*1.047=$+\
> frac{\pi}{3}$*0.785=$+\frac{\pi}{4}$*0.524=$+\frac{\pi}{6}$
> *0=$-0$*-0.524=$-\frac{\pi}{6}$*-0.785=$-\frac{\pi}{4}$*-1.
> 047=$-\frac{\pi}{3}$*-1.57=$-\frac{\pi}{2}$*-3.142=$-\pi$*-
> 4.712=$-\frac{3\pi}{2}$*6.28=$-2\pi$]{
> \getbuffer[goniometrickefunkce]
> \page
> }
>
> \stoptext
>
>
>
>
>
>
> Dne 15.2.2014 20:38, Lukáš Procházka napsal(a):
>
>> Hello,
>>
>> I just started experimenting with pgfplots package.
>>
>> I'd have two questions:
>>
>> 1) When plotting/loading a data file: Is it possible to specify the
>> comment mark, which is '#' and '%" by default? I'd need to treat ';' as a
>> comment mark, too.
>>
>> 2) How to pass coordinates of plot points by Lua?
>>
>> The following code:
>>
>> ----
>> \usemodule[tikz]
>> \usemodule[pgfplots]
>>
>> \startluacode
>> data = {{5, 15}, {20, 20}, {24, -24}}
>>
>> plot = function(data)
>> local str
>>
>> for i, v in ipairs(data) do
>> str = (str or "") .. "(" .. v[1] .. "," .. v[2] .. ")"
>> end
>>
>> print("Crds=", str)
>>
>> context(str)
>> end
>> \stopluacode
>>
>> \starttext
>> \starttikzpicture
>> \startaxis[]
>> \addplot[mark=none,color=red] coordinates {(11, 5) (12, 18)}; % THIS PLOT
>> IS OK
>> \addplot[mark=none,color=red] coordinates {\ctxlua{plot(data)}}; % THIS
>> PLOT HAS NO POINT (?!)
>> \stopaxis
>> \stoptikzpicture
>> \stoptext
>> ----
>>
>> gives error:
>>
>> "
>> ...
>> fonts > fallback modern rm 12pt is loaded
>> Crds= (5,15)(20,20)(24,-24)
>> Package pgfplots: Error! Sorry, I could not read the plot coordinates
>> near '(5,15)(20,20)(24,-24)'. Please check for format mistakes.
>> ! Package pgfplots Warning: the current plot has no coordinates (or all
>> have been filtered away)...
>> "
>>
>> Any idea from someone more familiar with pgfplots would be appreciated.
>>
>> TIA.
>>
>> Best regards,
>>
>> Lukas
>>
>>
>>
>>
>> ____________________________________________________________
>> _______________________
>> If your question is of interest to others as well, please add an entry to
>> the Wiki!
>>
>> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/
>> listinfo/ntg-context
>> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
>> archive  : http://foundry.supelec.fr/projects/contextrev/
>> wiki     : http://contextgarden.net
>> ____________________________________________________________
>> _______________________
>>
>
> ____________________________________________________________
> _______________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/
> listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
> archive  : http://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ____________________________________________________________
> _______________________
>



-- 
Atentamente

DesdeChaves

[-- Attachment #1.2: Type: text/html, Size: 9973 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2014-02-16 23:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-15 19:38 Lukáš Procházka
2014-02-16 19:32 ` Herbert Voss
2014-02-16 20:39   ` Lukáš Procházka
2014-02-16 21:56     ` Herbert Voss
2014-02-16 23:00 ` Jaroslav Hajtmar
2014-02-16 23:53   ` DesdeChaves [this message]
2014-02-17  0:11     ` Jaroslav Hajtmar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPBmU9FPSk65u2P58vZ300WbRM6KQpmn89+uuzMd1po94BQmnA@mail.gmail.com \
    --to=desdechaves@gmail.com \
    --cc=hajtmar@gyza.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).