Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread Herbert Voss

Am 15.02.2014 20:38, schrieb Lukáš Procházka:


...
fontsfallback 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.


As far as I know \addplot scans the coordinates in a way that a
macro is not possible here . However, write your coodinates into an
external file  and read it with

\addplot table {file.data};

 That will work.


Herbert
___
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
___


Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread Lukáš Procházka

Hello Herbert,

On Sun, 16 Feb 2014 20:32:11 +0100, Herbert Voss herbert.v...@fu-berlin.de 
wrote:


As far as I know \addplot scans the coordinates in a way that a
macro is not possible here . However, write your coodinates into an
external file  and read it with


I was aware of this solution; however, I was looking for another way due to 
performance reason and to avoid having too many temporary (data) files.



\addplot table {file.data};

  That will work.


It seems I found a more Lua way:


\usemodule[pgfplots]

\startluacode
  data = {{5, 15}, {20, 20}, {24, -24}}

  data2crds = function(data)
local str

for i, v in ipairs(data) do
  str = (str or ) .. ( .. v[1] .. , .. v[2] .. )
end

print(Crds=, str)

return str
  end

  --

  plot = function(data)
context.starttikzpicture()
  context.startaxis{}
context.addplot{mark=none,color=red}
  context(coordinates { .. data2crds(data) .. };)
  context.stopaxis()
context.stoptikzpicture()
  end
\stopluacode

\starttext
  \starttikzpicture
\startaxis[]
  \addplot[mark=none,color=red] coordinates {(11, 5) (12, 18)};
\stopaxis
  \stoptikzpicture

  \ctxlua{plot(data)}
\stoptext


Anyway, thanks.

Best regards,

Lukas



Herbert



--
Ing. Lukáš Procházka [mailto:l...@pontex.cz]
Pontex s. r. o.  [mailto:pon...@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 241 096 751
Fax: +420 244 461 038

t-Plot3.mkiv
Description: Binary data


t-Plot3.pdf
Description: Adobe PDF document
___
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
___

Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread Herbert Voss

Am 16.02.2014 21:39, schrieb Lukáš Procházka:


\startluacode
   data = {{5, 15}, {20, 20}, {24, -24}}

   data2crds = function(data)
 local str

 for i, v in ipairs(data) do
   str = (str or ) .. ( .. v[1] .. , .. v[2] .. )
 end

print(Crds=, str)

 return str
   end

   --

   plot = function(data)
 context.starttikzpicture()
   context.startaxis{}
 context.addplot{mark=none,color=red}




   context(coordinates { .. data2crds(data) .. };)


this line would be enough with \ctxlua{...}

Herbert


   context.stopaxis()
 context.stoptikzpicture()
   end
\stopluacode

\starttext
   \starttikzpicture
 \startaxis[]
   \addplot[mark=none,color=red] coordinates {(11, 5) (12, 18)};
 \stopaxis
   \stoptikzpicture

   \ctxlua{plot(data)}
\stoptext


Anyway, thanks.

Best regards,

Lukas



Herbert





___
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
___


Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread Jaroslav Hajtmar

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  : 

Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread DesdeChaves
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 hajt...@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
 

Re: [NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-16 Thread Jaroslav Hajtmar

Thanks Jorge
for the helpful and useful instructions. Sometimes it will certainly 
come in handy.


Jaroslav Hajtmar


Dne 17.2.2014 0:53, DesdeChaves napsal(a):

\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


___
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
___


[NTG-context] Pgfplots - passing point coordinates by Lua

2014-02-15 Thread Lukáš Procházka

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:


...
fontsfallback 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


--
Ing. Lukáš Procházka [mailto:l...@pontex.cz]
Pontex s. r. o.  [mailto:pon...@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4

Tel: +420 241 096 751
Fax: +420 244 461 038

t-Plot2.mkiv
Description: Binary data


t-Plot2.pdf
Description: Adobe PDF document
___
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
___