我添加了两张图片pgfplots plot graphics
。它们的高度相同(693px),但宽度不同(883px 和 1023px)。但是,我无法让它们以相同的高度绘制。
我该如何解决这个问题?我尝试过height
在这里和那里添加内容或通读 pgfplots 章节,但我确信我遗漏了一些明显的东西。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false,axis equal image]
\addplot graphics [
xmin=0,xmax=38.225,ymin=0,ymax=30,
includegraphics={draft}
] {883x693.png};
\end{axis}
\begin{axis}[enlargelimits=false,axis equal image,xshift=8cm]
\addplot graphics [
xmin=0,xmax=44.28,ymin=0,ymax=30,
includegraphics={draft}
] {1023x693.png};
\end{axis}
\end{tikzpicture}
\end{document}
(我希望绘制的图像具有与 PNG 文件相同数量的像素,但我认为这超出了 pgfplots 的范围?)
答案1
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
name=image1,
width=883px, height=693px, scale only axis,
enlargelimits=false,
]
\addplot graphics[xmin=0, xmax=38.225, ymin=0, ymax=30] {example-image};
\end{axis}
\begin{axis}[
name=image2, at={($(image1.south east)+(1cm,0)$)},
width=1023px, height=693px, scale only axis,
enlargelimits=false,
]
\addplot graphics[xmin=0, xmax=44.28, ymin=0, ymax=30] {example-image};
\end{axis}
\end{tikzpicture}
\end{document}
该px
单位位于此处:https://tex.stackexchange.com/a/41371/8650
为了测试该单元,可以使用以下代码:
\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west, draw, inner sep=0pt] {\includegraphics{anyimage.jpg}}; %inserts the image unscaled
\draw[red] (0,0) -- (468px,450px); %insert known size of image
\end{tikzpicture}
\end{document}