"Alex Vergara Gil" <a...@cphr.edu.cu> writes:

> From: "Richard Heck" <rgh...@lyx.org>
> Sent: Thursday, May 29, 2014 5:05 PM
>>> I might be *completely* off, but couldn't you achieve exactly this via
>>> defining converters? I have for example a converter defined, which
>>> "converts" plantuml source fields into uml graphs, i.e. it defines the
>>> call to compile them and return the graphs which are then inserted in
>>> the document?
>> Yes, that's more or less what I was suggesting.
>> rh

I just add comments inline

> Let's see if I understand:

-1. You define a *file type* in LyX under 
  Preferences > File Handling > File Formats
for the file type .pygr in which "Vector graphics format" is ticked!

0. You define a converter under
  Preferences > File Handling > Converters
which calls a script which executed files with the extension .pygr and
generates, as you suggest below, an svg.

> 1. I wrote a python script that produces the graphic I want

Exactly - and you give it a specific extension .pygr for "python
script which generates a graphic" which you defined above.

> 2. I insert it in LyX somehow I don't know, perhaps defining a
> converter from .py to svg, but this needs to be inside a module or
> every python script in LyX will try to be converted into a svg!! So a
> module is also needed

Use insert graphic and select *your .pygr* file as graphic - and Lyx
will do the rest of the conversion - i.e. use your converter to convert
the .pygr to an svg and other existing converters to generate the png
for the preview and the pdf / eps / ... for the final copmpilation of
the document.

> 3. LyX is the one who knows the correct size of the graphic so in
> principle if I produce a svg should be enough but in this way I need
> to produce a new svg every time the data change

Correct - if the input data changes, you have to generate the graph again
manually, or, if the "Converter file cache" is disabled, you just have
to close the document and open it again. 

Hope this helps,


> Take this simple script as example
> import numpy as np
> from numpy.random import randn
> import matplotlib as mpl
> import matplotlib.pyplot as plt
> np.random.seed(9221999)
> data = randn(75)
> plt.hist(data)
> which produce a graphic like this in spyder
> So basically I save this graphic to a svg and then I load it into LyX,
> but why not letting LyX doing this automatically if it already handles
> with python?? This is my question.
> Regards
> Alex

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, 
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      rai...@krugs.de

Skype:      RMkrug

PGP: 0x0F52F982

Attachment: pgp86MxwTSdD2.pgp
Description: PGP signature

Reply via email to