Pgfplots 网格线切割绘图线

Pgfplots 网格线切割绘图线

在这个图中,网格线切断了情节线,我怎么知道Pgfplots要把情节线画在网格“上方”?另外,我想给情节线“6”的右侧区域加阴影,该怎么做?

% !TEX options=--shell-escape
\documentclass{standalone}
\usepackage{pgfplots,filecontents}
\usepackage{sansmath}
\pgfplotsset{width=10cm,compat=1.16}
\begin{filecontents*}{filename3.txt}
0.5 20  0.96
1.0 20  1.91
1.5 20  2.87
2.0 20  3.82
2.5 20  4.78
3.0 20  5.73
3.5 20  6.69
4.0 20  7.64

0.5 30  1.00
1.0 30  2.01
1.5 30  3.01
2.0 30  4.01
2.5 30  5.02
3.0 30  6.02
3.5 30  7.02
4.0 30  8.02

\end{filecontents*}
\begin{document}
%\pgfplotsset{grid style={sand}}
%\pgfplotsset{minor grid style={densely dashed,red}}
%\pgfplotsset{major grid style={dotted,sand}}
\sffamily
\pgfplotsset{
  tick label style = {font=\sansmath\sffamily},
  every axis label = {font=\sansmath\sffamily},
  legend style = {font=\sansmath\sffamily},
  label style = {font=\sansmath\sffamily}
}
\begin{tikzpicture}
    \begin{axis}[
    xtick={0.5,1,...,4},
    ytick={20,30,...,100},
    tick label style={/pgf/number format/assume math mode=true, font=\scriptsize\sffamily},
    label style={font=\scriptsize\sffamily},
    ticklabel style={font=\scriptsize,fill=white},    every node near coord/.append style={font=\scriptsize},
    grid=both,
    major grid style={solid,line width=0.5pt,draw=brown!100},
    minor grid style={solid, line width=0.25pt, draw=brown!25}, 
    minor tick num=20,
     align =center, 
     title={\scriptsize Title},
     xlabel={x axis},
     ylabel={y axis},
     domain=-2:2,
     colormap/bluered,    
     view={0}{90}
      ]
%
    \addplot3[scale=3, 
         contour gnuplot={contour label style ={font=\sansmath\sffamily\scriptsize},levels={1,2,3,4,5,6,7,8,9,10,11,12}},
     very thick] file {filename3.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

答案1

使用set layers

\documentclass{standalone}
\usepackage{pgfplots,filecontents}
\usepackage{sansmath}
\pgfplotsset{width=10cm,compat=1.16}
\begin{filecontents*}{filename3.txt}
0.5 20  0.96
1.0 20  1.91
1.5 20  2.87
2.0 20  3.82
2.5 20  4.78
3.0 20  5.73
3.5 20  6.69
4.0 20  7.64

0.5 30  1.00
1.0 30  2.01
1.5 30  3.01
2.0 30  4.01
2.5 30  5.02
3.0 30  6.02
3.5 30  7.02
4.0 30  8.02

\end{filecontents*}
\begin{document}
%\pgfplotsset{grid style={sand}}
%\pgfplotsset{minor grid style={densely dashed,red}}
%\pgfplotsset{major grid style={dotted,sand}}
\sffamily
\pgfplotsset{
  tick label style = {font=\sansmath\sffamily},
  every axis label = {font=\sansmath\sffamily},
  legend style = {font=\sansmath\sffamily},
  label style = {font=\sansmath\sffamily}
}
\begin{tikzpicture}
    \begin{axis}[set layers,
    xtick={0.5,1,...,4},
    ytick={20,30,...,100},
    tick label style={/pgf/number format/assume math mode=true, font=\scriptsize\sffamily},
    label style={font=\scriptsize\sffamily},
    ticklabel style={font=\scriptsize,fill=white},    
    every node near coord/.append style={font=\scriptsize},
    grid=both,
    major grid style={solid,line width=0.5pt,draw=brown!100},
    minor grid style={solid, line width=0.25pt, draw=brown!25}, 
    minor tick num=20,
     align =center, 
     title={\scriptsize Title},
     xlabel={x axis},
     ylabel={y axis},
     domain=-2:2,
     colormap/bluered,    
     view={0}{90}
      ]
%
    \addplot3[%scale=3, %<- has no effect
         contour gnuplot={contour label style ={font=\sansmath\sffamily\scriptsize},levels={1,2,3,4,5,6,7,8,9,10,11,12}},
     very thick] file {filename3.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容