![定义一个系统方法将 pgf 图纳入 jpg 照片中](https://linux22.com/image/323582/%E5%AE%9A%E4%B9%89%E4%B8%80%E4%B8%AA%E7%B3%BB%E7%BB%9F%E6%96%B9%E6%B3%95%E5%B0%86%20pgf%20%E5%9B%BE%E7%BA%B3%E5%85%A5%20jpg%20%E7%85%A7%E7%89%87%E4%B8%AD.png)
我将图片添加到我的 LaTeX 文档中,并在每张图片上添加一个 PGFplot,显示拍摄照片时的环境条件(图表)。我有上述环境条件的时间序列(例如测量温度)。
下面是一个最小的示例代码,但显然还不够完美。现在,我想要实现的是:
- 定义一个名为 say 的方法
\includegraphicswithpgf
,以便当 LaTeX 放置我的图片时,它还会在同一张图片上绘制一个小的 PGF 图(长度的 1/3 和高度的 1/3),使用给定的格式标记、刻度、颜色等。绘制曲线的数值数据以正确格式保存在 tiem-series 中(文本文件,包含两列:时间和温度),存储在给定位置(待定义)。 - 生成的 pgfplot 的 x 限制(即时间窗口)应根据我拍摄照片的文件夹自动调整。换句话说,
xmin
和xmax
应根据文件夹名称(例如,Photos/January 或 Photos/June)而不同。范围等于 xmax-xmin,应可手动调整并以给定(默认)日期为中心。 - PGF 图与图像周长之间的偏移量应根据图像大小自动重新调整。
我对 LaTeX 编程(方法定义)不太在行。如能得到任何帮助,我将不胜感激。非常感谢您愿意提供的任何帮助。
来自意大利博洛尼亚的亲切问候
\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]
\addplot graphics [xmin=0,xmax=96,ymin=-1000,ymax=1096] {Febr/foto.jpg};
\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
\addplot[red,thick, samples=100]{20*sin(80*x)};
%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}
答案1
据我所知,控制轴的宽度和高度的唯一方法pgfplot
是使用width
和height
,并且pgfplot
将它们视为指导方针而不是规则。如果您想要精确,则需要使用\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
\addplot[red,thick, samples=100]{20*sin(80*x)};
%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}