0

I am trying to have a plot where the ticks on the y axis are 1, 1.004, 1.008, 1.012, 1.016, and 1.02. However, only the ticks 1, 1, 1.01, 1.01, 1.02, 1.02 are shown in the figure (see below). I was under the assumption that if we write ytick={1, 1.004, 1.008, 1.012, 1.016, 1.02} then that sets the values written at each y tick in the figure. Could someone please explain to me why this is wrong and furthermore how to have it so that the ticks in the y axis are for 1, 1.004, 1.008, 1.012, 1.016, and 1.02 ? My code is here:

\begin{figure}[ht]
    \centering
    \pgfplotsset{scaled y ticks=false}
    \begin{tikzpicture}
        \begin{axis}[name=plot, ymin=1, xtick={0, ..., 10}, ytick={1, 1.004, 1.008, 1.012, 1.016, 1.02}, xlabel={\LARGE$b_1$}]
            \addplot[black, mark=*]
            table{./data/ratio_of_estimated_value_versus_optimal_value.txt};\label{ratio_estimated_value_versus_optimal_value}
        \end{axis}
    \end{tikzpicture}
    
    \caption{Ratio of the Estimated Value of the Game and the Optimal Value of the Game}
    \label{fig:my_label}
\end{figure}

enter image description here

1
  • You've got a table data included here.
    – SolidMark
    Jun 25, 2021 at 4:04

1 Answer 1

3

For the decimal numbers to show up properly you should set precision=4 for displaying upto four significant figures.

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.18}

\begin{document}
\begin{figure}[ht]
    \centering
    \pgfplotsset{y tick label style={/pgf/number format/.cd, scaled y ticks=false, fixed, precision=4}} %<------------ Here
    \begin{tikzpicture}
        \begin{axis}[name=plot, xtick={0, ..., 10}, ytick={1, 1.004, 1.008, 1.012, 1.016, 1.02}, xlabel={\LARGE$b_1$}]
            \addplot[black, mark=*]
            table{./table.txt};\label{ratio_estimated_value_versus_optimal_value}
        \end{axis}
    \end{tikzpicture}
    
    \caption{Ratio of the Estimated Value of the Game and the Optimal Value of the Game}
    \label{fig:my_label}
\end{figure}
\end{document}

Precision missing

3
  • Bromuela thanks, that works! I don't quite understand a few things though. In the style curly braces (in the \pgfplotsset command), what do the "fixed" and "/pgf/number format/.cd" statements do? Thanks Jun 25, 2021 at 17:55
  • pgf/number format/.cd sets the default path to /pgf/number format. This allows you to call all the subkeys at once without needing to call everytime. Example: Instead of calling /pgf/number format/fixed,/pgf/number format/precision=2, you can shorten them to /pgf/number format/.cd, fixed, precision=2. And fixed just rounds the number to the fixed number of digits after decimal point. In this problem you really don't need it. You can use fixed zerofill instead to show trailing zeroes.
    – SolidMark
    Jun 25, 2021 at 19:22
  • Since this solved your problem, you may give a tick mark to this answer. I will appreciate greatly. Regards.
    – SolidMark
    Jun 25, 2021 at 19:23

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.