TransWikia.com

Adding an extra y tick, also adds an unnecessary one in the other part of the plot

TeX - LaTeX Asked by aiag on March 12, 2021

I want to construct a normal distribution probability plot. The x-axis is for the x-values of my bins, and the y axis shows the cumulative probability on the tick labels, but the y-values are the corresponding normal distribution z-values. The format that my professor uses is: major grid with labels for the y-values seen on my plot, and a minor grid with no labels, for y-values of 2 to 9 and 91 to 98 (the commented out line in the code).

The label-less minor grid is implemented using extra y ticks. However, when I add a y-value as an extra y tick, two minor grid lines appear. Why do they appear and how do I get rid of them?

documentclass[12pt,table]{report}
usepackage{tikz,pgfplots}
begin{document}
    begin{tikzpicture}[font=tiny,scale=1.6]
        begin{axis}[
            xtick pos=left,
            xtick={3.68,3.84,4.00,4.16,4.32,4.48,4.64,4.80,4.96,5.12},
            xticklabels={3.68,3.84,4.00,4.16,4.32,4.48,4.64,4.80,4.96,5.12},
            xticklabel style={shift={(0,0 |- {axis description cs:0,-0.97})}},
            ytick={-2.33,-1.28,-0.84,-0.52,-0.25,0.01,0.25,0.52,0.84,1.28,2.33},
            yticklabels={1.0,10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,99.0},
        %   extra y ticks={-2.05,-1.88,-1.75,-1.64,-1.55,-1.48,-1.41,
-1.34,1.34,1.41,1.55,1.64,1.75,1.88,2.05},   % All the extra ticks that I want
            extra y ticks={-2.05,-1.88,-1.75}, % best shows issue
            extra y tick style={tick style={draw=none},grid=minor},
            minor grid style={line width=.2pt,draw=red!120},
            extra y tick labels={},
            major grid style={line width=.2pt,draw=gray!120},
            grid=both,
            x axis line style={draw=none},
            axis x line=middle,
            axis y line=middle,
            xmin=3.6,
            xmax=5.27,
            ymin=-2.5,
            ymax=2.5,
            domain=3.599:5.2,
            ]
        end{axis}
    end{tikzpicture}
end{document}

enter image description here

One Answer

For pgfplots, a minor grid is N automatically placed ticks/grid lines, placed between each of the major ticks. The major ticks are placed at the specified tick locations.

So I think you want grid=major for the extra ticks, and to set the major grid style for the extra ticks alone:

extra y tick style={
  tick style={draw=none},
  grid=major,
  major grid style={line width=.2pt,draw=red!120}
},

Complete code:

documentclass[12pt,table]{report}
usepackage{pgfplots}
begin{document}
    begin{tikzpicture}[font=tiny,scale=1.6]
        begin{axis}[
            xtick pos=left,
            xtick={3.68,3.84,4.00,4.16,4.32,4.48,4.64,4.80,4.96,5.12},
            xticklabels={3.68,3.84,4.00,4.16,4.32,4.48,4.64,4.80,4.96,5.12},
            xticklabel style={shift={(0,0 |- {axis description cs:0,-0.97})}},
            ytick={-2.33,-1.28,-0.84,-0.52,-0.25,0.01,0.25,0.52,0.84,1.28,2.33},
            yticklabels={1.0,10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,99.0},
            extra y ticks={-2.05,-1.88,-1.75,-1.64,-1.55,-1.48,-1.41,
-1.34,1.34,1.41,1.55,1.64,1.75,1.88,2.05},   % All the extra ticks that I want
            extra y tick style={tick style={draw=none},grid=major, major grid style={line width=.2pt,draw=red!120}},
            extra y tick labels={},
            major grid style={line width=.2pt,draw=gray!120},
            grid=both,
            x axis line style={draw=none},
            axis x line=middle,
            axis y line=middle,
            xmin=3.6,
            xmax=5.27,
            ymin=-2.5,
            ymax=2.5,
            domain=3.599:5.2,
            ]
        end{axis}
    end{tikzpicture}
end{document}

enter image description here

Correct answer by Torbjørn T. on March 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP