2

my problem is that I need more digits in the y ticks. When used precision=4, the y label and y ticks are superposed. ¿How can I avoid this?

enter image description here

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
    \pgfplotsset{xmin=275, xmax=525, ymin=0.3135, ymax=0.3145}    
    \begin{tikzpicture}[scale=0.75]
        \begin{axis}[legend pos=south east,xlabel=$T\; \mathrm{(K)}$, ylabel=$f_{\mathrm{N_2}}$,xtick = {300,400,500},y tick label style={/pgf/number format/fixed,/pgf/number format/precision=4}]
            \addplot[color=red,style=ultra thick] 
            coordinates{
                (300,0.313962276936297)
                (400,0.314247035933962)
                (500,0.314270686043259)
            };
            \addplot[color=red, only marks,mark size=3.25pt] 
            coordinates{
                (300,0.313962276936297)
                (400,0.314247035933962)
                (500,0.314270686043259)
            };
        \end{axis}
    \end{tikzpicture}
\end{document}
1
  • 1
    For future questions, please always provide a full MWE starting with \documentclass{...} and loading all necessary packages.
    – Roland
    Oct 22, 2021 at 4:08

2 Answers 2

2

Like this:

With \pgfplotstableset{fixed zerofill,precision=0}

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}
    \pgfplotstableset{fixed zerofill,precision=0}
    \pgfplotsset{xmin=275, xmax=525, ymin=0.3135, ymax=0.3145}    
    \begin{tikzpicture}[scale=0.75]
        \begin{axis}[
            legend pos=south east,
            xlabel=$T\; \mathrm{(K)}$, 
            ylabel=$f_{\mathrm{N_2}}$,          
            xtick = {300,400,500},
            y  label style={yshift=5ex},
            y tick label style={/pgf/number format/fixed,/pgf/number format/precision=6},
            ]
            \addplot[color=red,style=ultra thick] 
            coordinates{
                (300,0.313962276936297)
                (400,0.314247035933962)
                (500,0.314270686043259)
            };
            \addplot[color=red, only marks,mark size=3.25pt] 
            coordinates{
                (300,0.313962276936297)
                (400,0.314247035933962)
                (500,0.314270686043259)
            };
        \end{axis}
    \end{tikzpicture}
    
\end{document}

enter image description here

0

Edit: One more (simple) solution, which use only pgfplots package. For diagrams is used only one \addplot command, added zerofill option to y tick label style, and defined is axis label position. With use of anchor=near ticklabel the ylabel is put near to y tick labels.

Since your MWE contain legend position options, to diagram is added a legend.

\documentclass[margin=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} % <--- new

\begin{document}
    \begin{tikzpicture}[scale=0.75]
        \begin{axis}[
            legend pos=south east,
            xlabel=$T$ (K),
            ylabel=$f_{\mathrm{N_2}}$,  ymin=0.3135, ymax=0.3145,  % <--- changed
            xtick = {300,400,500},
            ylabel style={anchor=near ticklabel},  % <=== changed, axis label is left of tick label
            y tick label style={/pgf/number format/.cd, zerofill,precision=4}, % <=== changed, added "zerofill" option
            ]
        \addplot +[red, ultra thick,                       % <--- changed, observe +
                   mark options={mark size=3pt,fill=red}]  % <--- new
            coordinates{
                (300,0.313962276936297)
                (400,0.314247035933962)
                (500,0.314270686043259)
                        };
        \end{axis}
    \end{tikzpicture}
\end{document}  

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .