fwiw, the following works well for me:
```
from pyqtgraph import exporters
exporter = exporters.SVGExporter(scene)
svg = exporter.export(toBytes=True)
pdf = cairosvg.svg2pdf(svg)
```
I note though that there's a bug in the SVG exporter such that the viewBox
is not set correctly, so I add the following hack to fix it:
```
import xml.etree.ElementTree as ET
ET.register_namespace("", "http://www.w3.org/2000/svg")
root = ET.fromstring(svg)
size = scene.parent().size()
width = size.width()
height = size.height()
root.attrib['viewBox'] = f"0 0 {width} {height}"
# FIXME: in 3.9 we can just do this:
#out = ET.tostring(root, encoding='UTF-8', xml_declaration=True)
with io.BytesIO() as bout:
ET.ElementTree(root).write(bout, encoding='UTF-8',
xml_declaration=True)
svg = bout.getvalue()
```
On Monday, November 23, 2020 at 4:09:53 AM UTC-8 [email protected] wrote:
> Dear Jerzy,
>
> The SVG export within the pyqtgraph NEVER exports the plot as seen in the
> interactive plot. See the attached file. The data are not filled, and the
> model is with SUPER low resolution. How Can I put this in my paper? I tried
> Inkscape with the exported files, with not much success. Maybe I did not
> get how to work with Inkscape, but after many hours trying to produce
> reasonable plots I simply give up.
>
> Try your self:
>
> https://github.com/3fon3fonov/exostriker
>
> load a data set, perform a model, and try to export. If you can provide me
> a reasonable .PDF from a SVG export I would be very happy to learn from you.
>
> My solution at the moment is to export to a custom version of the
> matplotlib exporter GUI, and from there to PDF.
>
> Yet, please agree with me, export directly in .PS, EPS or preferably .PDF
> is the best solution.
>
>
> I will open an Issue in the GitHub. Let's see what will be the outcome.
>
> Trifon
>
> On Tuesday, November 17, 2020 at 2:30:27 PM UTC+1 [email protected]
> wrote:
>
>>
>> Le 17/11/2020 à 08:02, Jonathán de Jesús Estrella Ramírez a écrit :
>>
>> Could you export the plot to PDF directly?, I'm in the same situation
>>
>> El lunes, 11 de marzo de 2019 a la(s) 16:52:47 UTC-6, [email protected]
>> escribió:
>>
>> Clarifications why using the pyqtgraph's .png and .svg export does not
>>> work for me:
>>>
>> /.../
>>>
>>
>>> Ok, so .png --> .pdf will not work!
>>>
>>>
>>> 2. The SVG output is also very strange:
>>>
>>> [image: test_svg_pdf_png.png]
>>> The last image is svg --> pdf --> png (so I can upload it.) The model of
>>> this export also looks like that there is no anti-aliasing. It does not
>>> look good on a paper.
>>>
>> Also, Trifon Trifonov complained, and used such words as "convenient and
>> fast"... But 'Convenient' is very relative, and 'fast' even more...
>>
>> I must say that I do not understand the issue. I had never any true
>> problems with SVG.* What* is strange in the .svg export?? That after
>> two conversions you lost the aliasing?
>>
>> Many people (including some hundreds of my students) look too often for
>> magic solutions, but there are some good universal tools. Try the
>> following:
>>
>> 1. Export duly the .svg file.
>>
>> 2. *Open it with Inkscape*. Edit it at your convenience.
>>
>> 3. Export as PDF, or as PNG, or whatever. But look what you are doing, in
>> particular if your soft didn't change the colour space...
>>
>> Too many people insist on including PNG graphics in their publications,
>> theses, etc. Well, those who include scientific plots as JPG are even
>> worse, but pdfLaTeX permits to include pdfs directly, and a pdf exported
>> from Inkscape has the "vector" resolution.
>>
>> ==
>>
>> Jerzy Karczmarczuk
>> /Caen, France/
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/b9cb012d-dc5f-4699-b901-51b64d58aa18n%40googlegroups.com.