Qt and exporting vector images - qt

I am using QPainter to draw some graphs on the screen and save these graphs as a raster images.
Is it possible to use the same logic I used for rasterizing these graphs to have them exported to vector images that I can use in a PDF?

You can use a QSvgGenerator as a "backend" to your QPainter, and you'll get an SVG document out of it. (The documentation has an example for how to do that.)
I don't know if you can use that directly in PDFs, but there are converters out there if you need a different vector graphics format.

Related

R: importing and saving SVG graphics

I have a complex task: to merge existing SVG image with barplots in R. I want to save the output file as a vector graphics as well. So I create the layout, in one of the subplots I create the barplot and now:
How can I load an existing SVG from the hard drive and then put it into the plot? I have tried grimport and grimport2 libraries but they fail to read my SVG. How should I prepare it? It is a simple sketch made in Inkscape, should I save it in any special way?
I'd prefer to use a library that is supported by Anaconda Cloud.
EDIT:
I menaged to read the .ps file with grimport and convert it to a picture object - it was crashing previously because I had a text box with non-standard font in the SVG and the library could not ready that properly (some encoding problems).
Now I am just looking for a way to put the Picture object on the layout, just as if I would use plot(runif(10), runif(10)) to have a scatterplot
grid.picture(picture_object[-1],x=x_coord,y=y_coord)
With the variables x_coord and y_coord I can manipulate the position of the image.

Can we rotate a 3-d png file that is ouput by gnuplot?

So, when we do something like: 'splot sin(x)*cos(y)' and we can rotate the ouput.
But if we do:
'set terminal png'
'set output "a.png"'
'splot sin(x)*cos(y)'
Then, is it possible to rotate the "a.png" file?
Thanks.
No, you cannot rotate a png file as if you were in interactive mode.
To display a 3D data set on a flat screen, any program must calculate a 2D projection in order to show the data. This projection is then rasterized, i.e. converted to pixels in order to be saved as png.
Already with the projection you loose all 3D information which would be necessary to perform any kind of 3D manipulation, besides that png looses even more information by the rasterization.
Gnuplot doesn't support any special data format which would be necessary to manipulate the 3D view later with a viewer.

The dilemma of plot saving formats - R/base plots

In my research work, when papers are to be communicated, the format could be either LaTeX or DOC/DOCX. This sends me into a dilemma.
I have generated PDFs (they can be easily included into a latex file) for certain plots using the base plot method. However, I would also like to have the PNG versions of the same plots (since MS Word does not accepts PDFs), and no, I do not want to rewrite codes! Further, the convert utility of ImageMagick is also not a preferable option, as there is a severe degradation in terms of resolution when one executes convert myFile.pdf myFile.png
What is the best way? Can we save a plot into a variable and then regenerate the plot to a png / jpg / tiff file?
Save to EPS format (see HowTo here). It is a vector format, and it should be recognizable by MS Word (you will need to import it as a picture) as well as LaTeX.

How to enlarge map/plot in R?

I plotted a map in R but when I export it the size is very small. How can I enlarge the map and still save it as a picture? (I know that I can save it as PDF and then it's a vector graphic - but I need to copy it to Power Point and also need a transparent background - I don't think that is possible with a PDF isn't it?)
As you can see here the map is way to small to use it in a Power Point slide:
If someone knows a good way to save it as vector graph that I can easily use in Power Point that would be perfect as well.
The png() function lets you specify width and height size in the default resolution of "px" and the defaults are 480 and 480. You can also supply a res argument in units of "ppi". If you have text you probably ought to specify point size >= 20 for legibility. I generally save my graphs as PDF and convert to PNG with an external program. However, the latest versions of PowerPoint will accept pdf formats. It is also possible to save as an .eps format.

Converting webGL html to SVG

I am using R, with the misc3d and rpanel libraries, to create a 3d image in webGL. I then need to embed the image into a PDF via Latex.
The 3d image renders fine and looks great - but I'm thinking I need to convert the webGL HTML file into an SVG or some other kind of vector graphics file which can be embedded in Latex.
Any suggestions on how to accomplish this?
Maybe I am wrong but this way doesn't make sense to me.
You have 3D coordinates
You render objects based on 3D coordinates to a 2D rasterized image using webGL
Then you want to extract 2D vector coordinates from the rendered image?
From the webGL framebuffer you can get the rasterized data (no vector information). So it is like converting a rasterized image (like png) to SVG. Since there is no way (I know) to get the vector information back from a rasterized image chances are high that the image will just be embedded in the SVG file. This wouldn't be a real benefit compared to a rasterized image.
Maybe you can use the vector informations (which you are using for drawing the webGL image) for drawing to a SVG image directly?
Is there a reason you can't use the rgl package instead (I'm not really familiar with rpanel, but I'm pretty sure that misc3d was originally design to work in conjunction with rgl) and use rgl.postscript(...,fmt="pdf") to export directly to PDF? rgl.postscript also offers an SVG option. The results are admittedly a little wonky sometimes (the underlying package it uses isn't completely reliable), but it's definitely the past of least resistance.
Also, I haven't tried it out myself, but I think the following article gives some information about embedding rgl images in their full, rotatable glory into PDFs: Levine, Richard A., Luke Tierney, Hadley Wickham, Eric Sampson, Dianne Cook, and David A. van Dyk. 2010. “Editorial: Publishing Animations, 3D Visualizations, and Movies in JCGS.” Journal of Computational and Graphical Statistics 19 (1) (January): 1–2. doi:10.1198/jcgs.2010.191ed. http://amstat.tandfonline.com/doi/abs/10.1198/jcgs.2010.191ed.

Resources