1

In this plot the grid lines are cutting the plot lines, how can I tell Pgfplots to draw the plot lines "above" the grid? Also I would like to shade the area right of plot line "6" how can this be done?

% !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}
0

Use 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}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.