[Tex/LaTex] Text in image scaled to same size as body text

captionsfloatsfontsizeMATLABpython

I am working on a research submission and my supervisor requires that any text on my graphs (e.g. axis labels, tick marks etc) are the same size as text in the main body of my report (including captions). In image snippet, all text should be the same size. All text above the caption is in the png file itself.

Example of my figure with caption and body text.

I am generating images in MATLAB/Python where I can manually set a font size before saving as a png file which overrides the image file that my LaTeX compiler uses.

Here is a minimum version of my tex file. The width argument is where the scaling of my image occurs.

\documentclass{report}

\usepackage{graphicx}
\usepackage{times}

\begin{document}


    \begin{figure}
        \includegraphics[width=1\linewidth]{plot-fig}
        \caption{This is my caption}
    \end{figure}

    This is my body text


\end{document}

And my MATLAB code to produce the png. It is in the same directory as the LaTeX. You can see the fontsize variable which I am manually changing.

figure
plot(1:5, 2*(1:5))
xlabel('This is my x label')
ylabel('This is my y label')
title('This is my title')

fontsize = 18;
ax = gca;
set(gca, 'FontSize', fontsize)

saveas(gcf, 'plot-fig.png')

My current solution is trial and error but this simply drives me insane: generate image, compile LaTeX, manually check text sizes by eye, adjust font size, repeat. This is further complicated by the scaling of images. Sometimes I need the images to take up two columns, other times a single column (and due to margins, the scaling is not a factor of 2). Also the dimensions of images are not always a consistent ratio as I am told to reduce the height of some images while keeping the same width (to avoid wasting space).

I would really appreciate a solution that could automate this process and give me some assurance that the font sizes are consistent.

Best Answer

It is best of course to avoid png for graphs or text, and use a scalable format such as pdf, but in either case your problem is [width=1\linewidth] which scales by an arbitrary amount.

Remove that and include the image at its natural size, then in matlab use the same text size as in your document.