From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/73124 Path: news.gmane.org!not-for-mail From: Paul Menzel Newsgroups: gmane.comp.tex.context Subject: Re: Lua and module gnuplot: Manipulate Gnuplot script with Lua Date: Mon, 12 Dec 2011 23:35:54 +0100 Message-ID: <1323729354.26949.105.camel@mattotaupa> References: <1323725964.26949.90.camel@mattotaupa> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0455375129==" X-Trace: dough.gmane.org 1323729386 10515 80.91.229.12 (12 Dec 2011 22:36:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 12 Dec 2011 22:36:26 +0000 (UTC) To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Mon Dec 12 23:36:20 2011 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RaETr-0000Pf-Cc for gctc-ntg-context-518@m.gmane.org; Mon, 12 Dec 2011 23:36:19 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 0A2E9CB163; Mon, 12 Dec 2011 23:36:18 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 3IzjfFtWt4oO; Mon, 12 Dec 2011 23:36:15 +0100 (CET) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 650B6CB164; Mon, 12 Dec 2011 23:36:15 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id A41BCCB164 for ; Mon, 12 Dec 2011 23:36:14 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vVBzjuVvsd0g for ; Mon, 12 Dec 2011 23:35:58 +0100 (CET) Original-Received: from filter1-til.mf.surf.net (filter1-til.mf.surf.net [194.171.167.217]) by balder.ntg.nl (Postfix) with ESMTP id 75705CB163 for ; Mon, 12 Dec 2011 23:35:58 +0100 (CET) Original-Received: from mail.gw90.de (mail.gw90.de [188.40.100.199]) by filter1-til.mf.surf.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id pBCMZvX9002579 for ; Mon, 12 Dec 2011 23:35:57 +0100 Original-Received: from f053045170.adsl.alicedsl.de ([78.53.45.170] helo=[192.168.178.21]) by mail.gw90.de with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1RaETX-0004zi-2P for ntg-context@ntg.nl; Mon, 12 Dec 2011 22:35:59 +0000 In-Reply-To: X-Mailer: Evolution 3.0.3-2 X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=188.40.100.199; country=DE; latitude=51.0000; longitude=9.0000; http://maps.google.com/maps?q=51.0000,9.0000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 08G8mzVpu - 81a2236e4f5e - 20111212 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.217 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.12 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:73124 Archived-At: --===============0455375129== Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-7puH+VtY8TgGRNuogWrp" --=-7puH+VtY8TgGRNuogWrp Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Am Montag, den 12.12.2011, 23:07 +0100 schrieb Mojca Miklavec: > On Mon, Dec 12, 2011 at 22:39, Paul Menzel wrote: > > I have two coefficients saved in a text file > > > > -0.157737135681261 > > -0.211443105668896 > > > > and I want to use them to plot a line with gnuplot. > > > > Having several of those files I want to use Lua to create the formula > > for the line for me. > > > > I have not yet figured out how to read values from a file in Lua and > > just tried to print a constant to the gnuplot command. > > > > I tried the following. > > > > \usemodule[gnuplot] > > > > \startGNUPLOTscript[lua] > > plot \ctxlua{context(1.2 * x + 3)} > > \stopGNUPLOTscript >=20 > This won't work. The reason is that contents between > \startGNUPLOTscript and \stopGNUPLOTscript are not parsed by ConTeXt > on purpose. >=20 > It was very very very painful if not impossible to get it right with > parsing. I often do things like > \def\E#1{$10^{#1}$} >=20 > \startGNUPLOTscript[name] > set logscale y > set format y "\\E{%T}" > plot sin(x) t '$\sin(x) [\E{3}]$' # usually something else with > logscale, but just to show the point > \stopGNUPLOTscript >=20 > and if ConTeXt starts parsing this it becomes a pure nightmare. > Realize that it can easily happen that ConTeXt then writes out > set logscale y > set format y " > E > plot sin(x) t '\math{\mathrm{sin}(x) [{10^{3}}]}' from expansion ...> >=20 >=20 >=20 > However, \startGNUPLOTinclusions is parsed and you could in theory > misuse that, but it would be very bad coding practice. Thank you very much for your explanations. > It would be a lot better to come up with some proposal how to change > the interface to enable what you want to do. (To be honest, it is > still on my todo list to migrate to Aditya's filter module in the > background, but I don't find the courage to start since I have no idea > how many bugs will creep in.) I do not know this very well, so I do not know what would change when using the filter module. I guess in the end being able to pass a plt-file to `\startGNUPLOTscript` would be enough. > But a serious question: what *exactly* do you want to do with lua that > you are unable to do with some (even though ugly) gnuplot trickery? I do not know. This was just a product out of my ignorance. Searching for `gnuplot load parameters` or something like that only turned `fit` related stuff. Thinking about this, I should have searched harder or looked at the manual or examples. > Gnuplot does have some basic programmable capabilities. I can imagine > that you should be able to do something like: >=20 > # params.dat > a=3D-0.157737135681261 > b=3D-0.211443105668896 >=20 > \startGNUPLOTinclusions > f(x,a,b)=3Da*x+b > \stopGNUPLOTinclusions >=20 > \startGNUPLOTscript[name] > load 'params.dat' > plot f(x,a,b) > \stopGNUPLOTscript > > And if needed you can create params.dat on the fly (but I believe that > the same should be doable even if you start with just pure data values > and do some dirty tricks in gnuplot). That pretty much what I need. Thank you! What I do is to do simulations and then do the linear regression using R [1]. (I know gnuplot can do that too, but I got some errors with it and using R seems easier for me.) Then the calculated coefficient are saved to a separate file because having discovered your nice gnuplot module I want to use that for plotting. Now I need to read in those parameters. I guess I have to compose the plot manually but those parameters were essential. > Yet another trick could be to create a text file on the fly with lua > (if you really really really need that) and then your script only says > something like. >=20 > # bla.plt created on the fly with lua scripts > plot 1.2 * x + 3 >=20 > \startGNUPLOTscript[bla] > load 'bla.plt' > \stopGNUPLOTscript >=20 > I leave creating a suitable 'bla.plt' with lua to others ... That is in my opinion the best solution. If I want to script something there are enough solutions already. Being able to use the tools of once choice and to insert the result should fit everyone=E2=80=99s need. Thank you again very much for your help. Thanks, Paul [1] http://www.r-project.org/ --=-7puH+VtY8TgGRNuogWrp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEABECAAYFAk7mgcsACgkQPX1aK2wOHVio3gCfS8GYWLB5+xVJthJOm10YmfNj eqkAn3cC4WhLHVsCKa4qEEfeCA8OBIUR =4UWa -----END PGP SIGNATURE----- --=-7puH+VtY8TgGRNuogWrp-- --===============0455375129== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ 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 ___________________________________________________________________________________ --===============0455375129==--