# Define a systematic method to include pgf plots into jpg photos

I am including images into my LaTeX document and, overlapped to each image, I am adding a PGFplot, showing (a graph with) the environmental conditions when the photo was taken. I have the time-series of the above mentioned environmental conditions (for instance measured temperature).

A minimal example code follows below but is clearly far away from perfection. Now, what I want to achieve is:

1. Define a method, named say \includegraphicswithpgf, so that when LaTeX places my picture, it also draws on that same pictures a small PGF plots (1/3 of length and 1/3 of height), using given format for labels, ticks, colours, etc. Numerical data to draw the curve are saved on tiem-series properly formatted (text file, contained two columns: time and temperature) stored in a given location (to be defined).
2. The x limits of the produced pgfplot (i.e., the time window) should adjust automatically, depending on the folder from which I am taking my pictures. IN other words, xmin and xmax, should differ depending on the folder NAME (Photos/January, or Photos/June for example). The range, which equals xmax-xmin, should be manually adjustable and centered in a given (default) date.
3. The offset separating the PGF plot from the image perimeter should rescale adjust automatically based on image size.

I am not really good with LaTeX programming (definition of methods). Any help is greatly appreciated. Thank you very much for any help you might be willing to give.

Kind regards from Bologna, Italy

    \documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{
label style={anchor=near ticklabel},
xlabel style={yshift=0.5em},
ylabel style={yshift=-1em},
tick label style={font=\footnotesize },
label style={font=\footnotesize},
legend style={font=\footnotesize},
title style={font=\tiny}}

\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,width=13cm, height=8.66cm,xtick={}, xticklabel=\empty, yticklabel=\empty]
\end{axis}

\begin{axis}[tiny, xshift=.75cm, yshift=1cm, yellow, ymin=-30, ymax=30,
height=3cm, width=8cm, axis background/.style={opacity=0, fill=gray!90},
axis y line=left, axis x line = bottom,
xlabel={days in October 2012}, %ylabel={Temp},
xtick={-5,-4,...,5}            %just a test
]
%just as example, a sinusoid
%add the exact time when the picture was taken
\addplot[white, dashed] coordinates { (0, -25) (0,25)};
\addplot[white, thin, opacity=0.4] coordinates { (0, -25) (0,25)};
\end{axis}
\end{tikzpicture}
\caption{Evidence taken on Febr. 14-th, 2014, at Lido di Dante, approximately 2 km North of \emph{Bevano} inlet.  showing how slumping eroded to dune foot leading to erosion of the whole structure. Figures includes wave climate measured off-shore.}
\end{figure}

\end{document}


AFAIK, the only way to control the width and height of a pgfplot axis is with width and height, and pgfplot regards them more as guidelines than rules. If you want precision, you will need to use \resizebox.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{
%label style={anchor=near ticklabel},
xlabel style={yshift=0.5em},
ylabel style={yshift=-1em},
tick label style={font=\footnotesize },
label style={font=\footnotesize},
legend style={font=\footnotesize},
title style={font=\tiny}}

\usepackage{mwe}% provides example-image (when first installed)
\newsavebox{\tempbox}

\begin{document}

\begin{figure}
\savebox{\tempbox}{\includegraphics{example-image}}% now have size
\usebox\tempbox% align to lower right corner
\begin{tikzpicture}[overlay,xshift={-0.9\wd\tempbox},yshift={0.1\ht\tempbox}]
\begin{axis}[tiny, width={0.5\wd\tempbox}, height={0.5\ht\tempbox}, yellow, ymin=-30, ymax=30,
axis background/.style={opacity=0, fill=gray!90},
axis y line=left, axis x line = bottom,
xlabel={days in October 2012}, %ylabel={Temp},
xtick={-5,-4,...,5}            %just a test
]
%just as example, a sinusoid