이미지에 pgfplots 그리드 그리기

이미지에 pgfplots 그리드 그리기

480x800 이미지에 pgfplots 그리드를 그리고 싶습니다. 아래 코드를 사용하면 그리드가 플롯되었지만 이미지가 표시되지 않는 것을 볼 수 있습니다.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz} 
\usepackage{pgfplots} 
\pgfplotsset{compat=1.18}
\begin{document}
\def\fname{/media/sf_work/demo.png}
\begin{tikzpicture}
\begin{axis}[
        grid = both,scale=.5,
        width=480,
        height=800,
        , minor tick num=3
        , grid style={draw=gray!10,line width=.1pt}
        , major grid style={line width=0.5pt,draw=gray!50}
        , axis line style={latex-latex}
        , xticklabels = \empty
        , yticklabels = \empty
        , draw=blue!20
    ]
  \node[] (image) at (axis cs:240,400) {\includegraphics[]{\fname}};
\end{axis}
\end{tikzpicture} 
\end{document}

산출: 여기에 이미지 설명을 입력하세요

답변1

widthand length(생성된 사진의 물리적 크기) 를 x 및 y 값 범위와 혼합합니다 . 그림은 벡터이므로 여기에서 픽셀을 가지고 놀 수는 없습니다. 적어도 그리 쉽지는 않습니다.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\def\fname{/media/sf_work/demo.png}
\begin{tikzpicture}
\begin{axis}[
    grid = both, %scale removed, here it messes things up
        width=4.8cm,
        height=8cm,
        xmin=0, xmax=480, ymin=0, ymax=800,
        , minor tick num=3
        , grid style={draw=gray!10,line width=.1pt}
        , major grid style={line width=0.5pt,draw=gray!50}
        , axis line style={latex-latex}
        , xticklabels = \empty
        , yticklabels = \empty
        , draw=blue!20
    ]
    % axis cs is not needed
  \node[] (image) at (axis cs:240,400) {\includegraphics[width=2cm]{example-image-duck}};
\end{axis}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

pgfplots는 x 및 y 레이블이 없더라도 공간을 추가하며 일반적으로 그리드는아래에사진.

관련 정보