For quite some time, I have been searching for a way to insert axis tick labels of plots within the frame/area of the plot. I think it less disturbs the axis labels themselves. However, there is an issue at the origin where the x tick and y tick labels overlap. One way is to place the tick labels differently as follows:
It is slightly repetitive but at least all the information is there. I am wondering whether there is a way to "automatically" achieve this with pgfplots?
The tikz code is provided below:
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage[libertine]{newtxmath} % Math fonts
\usepackage{filecontents}
\begin{filecontents*}{testt.txt}
-1 -1
1 2
2 4
3 2
4 1
5 0
\end{filecontents*}
\begin{filecontents*}{testp.txt}
-1 6
1 4
2 2
3 1.5
4 2
5 3
\end{filecontents*}
\begin{document}
\begin{tikzpicture}[scale=2]
\fill[gray!10] (1,1) rectangle (4,4);
\node[rotate=90,above,font=\small] at (1,2.5) {intensity};
\node[below,font=\small] at (2.5,1) {size};
\begin{scope}
\clip (1,1) rectangle (4,4);
% grid
\foreach \i in {1,2,...,4}
{
\draw[gray!50] (\i,1) -- (\i,4);
\draw[gray!50] (1,\i) -- (4,\i);
}
% axis labels
\foreach \i in {2,3}
{
\node[gray!50,above,fill=gray!10,font=\tiny,inner sep=2pt,yshift=2pt] at (\i,1) {\i};
\node[gray!50,below,fill=gray!10,font=\tiny,inner sep=2pt,yshift=-2pt] at (\i,4) {\i};
\node[gray!50,below,fill=gray!10,font=\tiny,inner sep=2pt,xshift=2pt,rotate=90] at (1,\i) {\i};
\node[gray!50,above,fill=gray!10,font=\tiny,inner sep=2pt,xshift=-2pt,rotate=90] at (4,\i) {\i};
}
% corner labels
\node[gray!50,above left,fill=gray!10,font=\tiny,inner sep=2pt,xshift=-2pt,rotate=90] at (4,4) {4};
\node[gray!50,below right,fill=gray!10,font=\tiny,inner sep=2pt,yshift=-2pt] at (1,4) {1};
\node[gray!50,above left,fill=gray!10,font=\tiny,inner sep=2pt,yshift=2pt] at (4,1) {4};
\node[gray!50,below right,fill=gray!10,font=\tiny,inner sep=2pt,xshift=2pt,rotate=90] at (1,1) {1};
\draw[line width=1pt] plot[smooth] file {testt.txt};
\draw[line width=1pt,red] plot[smooth] file {testp.txt};
\end{scope}
\draw[color=gray] (1,1) rectangle (4,4);
\end{tikzpicture}
\end{document}