Keeping custom figure font size when using print() - font-size

I am running a self written script which plots and saves a large number (over 100) of graphs and I have set the axis text to 18pt using
set(0,'defaultAxesFontSize',18);
The figures are saved as .fig using the savefig() command and the font size is correct. But when I save them as .jpg (to be included in a LaTeX report) using print(name, '-djpeg') the font size is the regular default size (guessing about 10pt). If I open one of the .fig files and do File > Save as, the resulting .jpg file has the desired font size.
How can I solve this in the command line?
EDIT:
I have tried using saveas(gcf, name, 'jpg') as well but the result is the same.
EDIT 2:
Here is a minimal example
set(0,'defaultAxesFontSize',18);
x = linspace(0, 2*pi);
plot(x, sin(x))
title('Sine')
xlabel('x')
ylabel('y')
legend('y = sin(x)')
fig = strcat('Sine')
savefig(fig)
print(fig, '-djpeg')
Tanks
Kajsa

I needed to set the paper position mode to auto to make the print the same size as the figure on screen.
This does that for all figures
set(0,'defaultAxesFontSize',18);
set(0,'DefaultFigurePaperPositionMode','auto')
x = linspace(0, 2*pi);
figure(1)
plot(x, sin(x))
title('Sine')
xlabel('x')
ylabel('y')
legend('y = sin(x)')
fig = strcat('Sine')
savefig(fig)
print(fig, '-djpeg')
Works great.

Related

knitr not aligning figures to center when image is expanded (.pdf document)

I am trying to increase the size of an image in a .pdf document using knitr, but when I try to do this the image shifts to the right and off the page. Here is the syntax I am using:
```{r test_image, echo = FALSE, out.width = '150%', fig.align = 'center'}
knitr::include_graphics("test_image.png")
```
I have also tried inserting fig.height and fig.width to adjust the height (instead of using out.width) but I still get the same thing. I have also tried fig.align = 'left' to keep the image on the page but that does not solve the issue either.
Has anyone else noticed this behavior? Is there a way to maintain the image centering when increasing the image size?
My thoughts.
I think, that this problem exists because of "big amount" of whitespace on left and right sides of your picture.
You can trim it manually and add after with knitr::include_graphics or do it with latex straightaway:
Add to your header:
header-includes:
- \usepackage{graphicx}
Add your pic
\includegraphics [trim={5cm 0 5cm 0},clip]{Ml6KL.png}
#you can also customize your width/height
#\includegraphics [trim={5cm 0 5cm 0},clip, width = XX, height = XX]{Ml6KL.png}
An output:
P.S. If you can - try to find better versions of first two logos(or scale < 1). As you can see - the quality leaves much to be desired...

How to create a custom Dataset for YOLO v3 by LabelImg

I have used LabelImg Save as YOLO option to save my label in the form of .txt with the format like
6 0.333984 0.585938 0.199219 0.160156
But I want it to be in this format
path/to/img1.jpg 50,100,150,200,0 30,50,200,120,3
path/to/img2.jpg 120,300,250,600,2
How do I achieve that?
YOLO uses relative values rather than raw pixel values. In other words, the format is:
center-x center-y width height
Where center-x is the percentage of the width. In other words, if the image is 800px wide, and the center-x is at 400px, the center-x would be written as 0.5.
So your Labellmg values are already correct for training YOLO. Also, in YOLO v3 you do actually need them all to be separate .txt files, rather than in one big long file. So you're already good to go.
Disagree with the above answer. Not all implementations require percentage of width, center or height and the implementations of Yolo I used require a single train.txt file. A specific one for example https://github.com/qqwweee/keras-yolo3 requires exact format mentioned in the question but the 4 numbers are coordinates top right x, top right y, bottom right x, bottom right y followed by class number. Nevertheless you can use those text files and merge them together in a csv including the name of the image in a column as well. This can be done using glob or pandas library. You can do the width, height calculations in the csv for the whole column at once. Then add the path to the complete column at once and convert it into a text file and it will be ready for input.

gnuplot epslatex unable to get replot

When I use replot in the epslatex terminal, anything I replot is not showing up in the final output.
reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone
set output 'plots.tex'
set size square
plot sin(x)
replot cos(x)
set output
When I use , and plot in the same line, I get correct outputs.
reset session
set terminal epslatex size 5.0in,4in color colortext font ',10' standalone
set output 'plots.tex'
set size square
plot sin(x), cos(x)
set output
replot is very convenient becuase I can use set and change settings.
My question is how to use replot in gnuplot that prints in LaTeX.
In gnuplot both commands are different. Using plot sin(x) followed by replot cos(x) draws two plots: one with sin(x) and another one with the result of the previous plot command (ie sin(x)) and cos(x). Indeed
plot sin(x)
replot cos(x)
is absolutely equivalent to
plot sin(x)
plot sin(x), cos(x)
If you display the 'plots-inc.eps' or if you change the terminal to pdf, you have two pages, the first with the plot of sin(x) and the second with both.
The plots.tex file is supposed to be included in a some tex source and only contains one plot. The actual function that is plotted in the .tex file is the last one (with sin(x) and cos(x)). This code is adapted to dvi output and if you format it with latex plots.tex (and not pdflatex plots.tex) and view the .dvi file with xdvi (or whatever), you can verify that a plot with both functions is present. For unknown reasons, with pdflatex, only the sin(x) appears (but both are in the .tex code and there is the legend for cos(x)).
Here is what I get in the .dvi file:
We can do a zoom on this dvi file.
And compare it to the second plot if we use a pdf terminal.
As you can see, the plot rendering is worse with the dvi file and the function is smoother with the pdf output.
I think the problem is that the epslatex terminal is a very old driver. It was the default in the nineties, but with modern TeX engines, almost no one uses it anymore and I am not sure that it is actively maintained.
This probably explains the problems : the incomplete plot with pdflatex and the lower quality of the rendering. Most probably this driver has never really been adapted to engines like pdflatex or lualatex.
Unless you absolutely need dvi, I would suggest you to switch to another driver. Generate your plots as pdf and use \includegraphics to load them. The plot quality will be increased, but you will also gain all the flexibility of \includegraphics to resize, rotate, clip or do whatever you want to your plots.
Please note that the pdf driver will generate one plot per page and with your initial code there are two plots. You can include a specific page (ie plot) of the pdf with the 'page=' option of \includegraphics, but the simpler is to select different output files per plot.
set output 'plots.pdf'
plot sin(x)
set output 'plots2.pdf'
replot cos(x)

set papersize Printing with Ghostscript.NET

I'm printing some pdf's using Ghostscript.NET
this is my config.
List<string> switches = new List<string>
{
"-empty",
"-dPrinted",
"-dFirstPage=1",
"-dLastPage=1",
"-dPrinted",
"-dBATCH",
"-dNOPAUSE",
"-dNOSAFER",
"-dNumCopies=1",
"-sDEVICE=mswinpr2",
#"-sFONTPATH=" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts),
"-sOutputFile=%printer%" + printQueue.FullName,
"-f",
inputFile
};
It works pretty well but my paper size is a custom paper 6.5in x 8.5in, my problem is when I print silent to my ricoh printer, try to print in letter.
How can i do to set my paper size in my switches or force the printer to render it properly.
If i print manually must select the paper and bin manually and all print's perfect.
The mswinpr2 device uses Windows to do the printing, in particular the media size is set by the printer canvas.
So the answer is to set the default media selection of your printer to the required media size before you start printing.
You can set the paper size with "-sPAPERSIZE=a4" you can see Paper sizes known to Ghostscript.
or you can set it by height and width
"-dDEVICEWIDTHPOINTS=w"
"-dDEVICEHEIGHTPOINTS=h"
Where w be the desired paper width and h be the desired paper height in points (units of 1/72 of an inch).

How to get a normalized font size for a PDF using PDFBox

I am working on a project that parses pdf files and extracts text. I am using the TextPosition class to generate a data-structure containing the position and size of each character in the pdf file.
I am running into an issue where there is a custom defined Type 3 font inside the pdf with really large characters. Font that appears to be about font size 9 on the screen are actually set to a font size of 0.24. I attempted to try and use the fontDescriptor to try and get the cap height of the font and use that instead, but it is null. Also, there is another font on the page that has a large amount of white-space above and below it, making the Cap height unusable. Here is what the TextPosition class looks like for a random character on the page.
I was hoping that someone knew how to get the correct pt font size?
Thanks

Resources