1

I use the following code to create the plot shown below.

\documentclass[a4paper]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{pgfplotstable}

\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\Large},
            tick label style={font=\Large}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
    xmode=log,
    ymode=log,
    enable tick line clipping=false,
    width=9cm,
    height=7cm,
    axis line style=semithick,
    x tick style={black,semithick},
    xmin=1,xmax=100,
    xtick={1,10,100},
    xtick pos=bottom,
    minor x tick num=9,
    xtick align=outside,
    y tick style={black,semithick},
    ymin=0.1,ymax=10,
    ytick={0.1,1,10},
    ytick pos=left,
    minor y tick num=9,
    ytick align=outside,
]        
    \addplot [blue,mark=*,mark options={scale=1.5,blue}]
         table [x=x,y=y] {
         x      y
         2      0.5
         10     1
         50     3
    };

\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}

enter image description here

When I want to show an additional minor tick label, let say 3, in y axis by simply adding 3 in the y axis range ytick={0.1,1,3,10}, it produces this graph enter image description here

The tick 10^0.48 is a minor tick but its length somehow became equal to the major tick length. Also, why did the rest of the minor ticks disappeared? I used the command minor y tick num=9, in the code. How can I write 3 instead of 10^0.48 and add any minor tick label I want to, e.g. 0.5 or 7?

1

I guess that you are searching for something like the following, right?

When adding non-equidistant ticks the automatically computed minor ticks disappear. This is an intended behaviour (and usually what you want).

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmode=log,
        ymode=log,
        xmin=1,xmax=100,
        ymin=0.1,ymax=10,
        xtick={1,10,100},
        ytick={0.1,1,10},
        xtick pos=bottom,
        ytick pos=left,
        xtick align=outside,
        ytick align=outside,
        tick style={black,semithick},
        % these don't have any effect, because they are the default anyway
%        minor x tick num=9,
%        minor y tick num=9,
        % add an extra tick with the corresponding label
        extra y ticks={3.5},
        extra y tick labels={3.5},
        % and change the style of the tick to the ones of the minor ticks
        extra tick style={
            tickwidth=\pgfkeysvalueof{/pgfplots/minor tick length},
        },
    ]
        \addplot table [x=x,y=y] {
             x      y
             2      0.5
             10     1
             50     3
        };

    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

7
  • Thank you Stefan. Very helpful. I manage to get this far using your code y tick style={black,semithick}, ymin=0.3,ymax=4, ytick={0.1,1}, y tick labels={1}, ytick pos=left, ytick align=outside, extra y ticks={0.3,0.4,2,3,4}, extra y tick labels={0.3,0.4,2,3,4}, extra tick style={ tickwidth=\pgfkeysvalueof{/pgfplots/minor tick length}}, Now I changed the y axis limits, and I wish to change the number format of 10^0 to 1. Would that be possible?
    – Gagik
    Feb 19 '19 at 19:00
  • Do you mean you want to replace all instances of 10^x by the integer value? If so, you could simply add log ticks with fixed point to the axis options. Feb 19 '19 at 19:26
  • No, I want to replace only 10^0 with 1 on the y axis. Because I changed the limit ymin=0.3,ymax=4and I only want to show the tick labels 0.3,0.4,1,2,3,4. However, since 1 is a major tick, it shows as 10^0.
    – Gagik
    Feb 20 '19 at 16:00
  • Then I recommend just replacing the values in extra y ticks and extra y tick labels with your stated numbers and add yticklabels=\empty to the axis options. Feb 20 '19 at 20:54
  • I personally think that this looks really horrible. I would only add ticklabels to ymin,1,ymax. There should not be a problem to find out what values belong to the non-numbered ticks. And is it really necessary to show these small y range in a logarithmic axis? Feb 20 '19 at 20:58

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.