ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jaroslav Hajtmar <hajtmar@gyza.cz>
To: ntg-context@ntg.nl
Subject: Re: Pgfplots - passing point coordinates by Lua
Date: Mon, 17 Feb 2014 00:00:00 +0100	[thread overview]
Message-ID: <530142F0.5040703@gyza.cz> (raw)
In-Reply-To: <op.xbb8uzjef14xzu@lkzd-2013>

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
___________________________________________________________________________________


  parent reply	other threads:[~2014-02-16 23:00 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 [this message]
2014-02-16 23:53   ` DesdeChaves
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=530142F0.5040703@gyza.cz \
    --to=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).