0

I have the following image in my file. How can I add units next to the numbers? I'd like the units to be in volts. I just added a part of the tikz code bellow.

enter image description here

\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\begin{tikzpicture}

\begin{axis}[%
width=0.951\figurewidth,
height=\figureheight,
at={(0\figurewidth,0\figureheight)},
scale only axis,
xmin=1,
xmax=1250,
xtick={\empty},
ymin=4,
ymax=6,
axis background/.style={fill=white},
xmajorgrids,
ymajorgrids,
y unit = \volt
]
\addplot [color=mycolor1, forget plot]
table[row sep=crcr]{%
1   5\\
2   4.90000000000009\\
3   5\\
5   5\\
};
\end{axis}
\end{tikzpicture}%
  • 2
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Moriambar May 15 '17 at 16:23
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – samcarter_is_at_topanswers.xyz Mar 7 '18 at 16:08
2

If you really want the unit in every tick (I would prefer an axis label stating the units, but let's not dispute tastes...), the best option is using siunitx:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[
    ]
    \begin{axis}[%
    xmin=1,
    xmax=5,
    xtick={\empty},
    ymin=4,
    ymax=6,
    axis background/.style={fill=white},
    yticklabel={\SI[round-mode=places, round-precision=1]{\tick}{V}}
    ]
    \addplot [color=blue, forget plot]
    table[row sep=crcr]{%
        1   4.1\\
        2   4.9\\
        3   5\\
        5   5.6\\
    };
\end{axis}     
\end{tikzpicture}
\end{document}

output

This is explained in section 4.15 of the pgfplots manual, "Ticks Options".

(BTW, this is an example of a Minimal Working Example --- MWE. USe it on your next question! )

(PS, thanks to @Ulrike Fiecher, see siunitx in pgfplots label description infinite loop?)

| 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.