Hi i want to put this simbol "%" in the tick labels only in the x axis how can i do?
[Tex/LaTex] PGFPlots % in ticks labels
pgfplots
Related Solutions
This doesn't directly solve this question, but it solved my problem: I wanted a x axis with buffer sizes and units (B, KiB, MiB, GiB). For this the dynamic axis style worked, but there is a better solution:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{ifthen}
\pgfplotsset{
byte x achsis log/.style={
xticklabel={%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed,/pgf/number format/.cd,fixed,fixed zerofill}
\pgfmathparse{2^\tick}
\sizetobytes{\pgfmathresult}
},
xticklabel style={rotate=90,anchor=east, font=\small},
},
}
\def\less#1#2#3{%
\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed,/pgf/number format/.cd,fixed,fixed zerofill,precision=0}%
\def\arga{#1}\edef\earga{\arga}%
\def\argb{#2}\edef\eargb{\argb}%
\pgfmathparse{\arga < \argb}%
\pgfmathprintnumberto[verbatim]{\pgfmathresult}{\lessresult}%
\xdef#3{\lessresult}%
\endgroup%
}
\def\sizetobytes#1{%
\begingroup%
\def\size{#1}%
\less{\size}{1024}{\result}%
\ifthenelse{\equal{\result}{1}}%
{%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed,%
/pgf/number format/.cd,fixed,fixed zerofill,precision=0,set thousands separator={}}%
\pgfmathprintnumber{\size}$\;$B%
}%
{%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed,%
/pgf/number format/.cd,fixed,fixed zerofill,precision=1,set thousands separator={}}%
\less{\size}{1048576}{\result}%
\ifthenelse{\equal{\result}{1}}{%
\pgfmathparse{divide(\size,1024)}%
\pgfmathprintnumber{\pgfmathresult}$\;$KiB%
}%
{%
\less{\size}{1073741824}{\result}%
\ifthenelse{\equal{\result}{1}}{%
\pgfmathparse{divide(\size,1048576)}%
\pgfmathprintnumber{\pgfmathresult}$\;$MiB%
}%
{%
\pgfmathparse{divide(\size,1073741824)}%
\pgfmathprintnumber{\pgfmathresult}$\;$GiB%
}%
}%
}%
\endgroup%
}%
\begin{document}
\begin{tikzpicture}%
\begin{axis} [width=7cm,
grid=major,
xmode=log,
log basis x=2,
byte x achsis log,
xminorticks=true,
try min ticks log=13
]%
\addplot coordinates { (1,2) (2048,4) (3000,6) (3000000,7)};
\end{axis}%
\end{tikzpicture}%
\end{document}
From the pgfplots
manual, section 4.14 “Tick Options”, p. 241:
/pgfplots/ytickten={<exponent base 10 list>}
These options allow to place ticks at selected positions 10k; k ∈
{<exponent base 10 list>}
. They are only used for logplots. The syntax for{<exponent base 10 list>}
is the same as above forxtick={<list>}
orytick={<list>}
.Using
xtickten={1,2,3,4}
is equivalent toxtick={1e1,1e2,1e3,1e4}
, but it requires fewer computational time and it allows to use the short syntaxxtickten={1,...,4}
.
… and it adds back the minor “log-ticks” marks.
Code
\documentclass[tikz]{standalone}
\usepackage{pgfplots, amsmath}
\pgfplotsset{width=7cm,compat=newest}
\pgfkeys{/pgf/number format/set thousands separator = }
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
xlabel = {A},
ylabel = {B},
ytickten = {0,...,6},
]
\addplot[
color = red,
mark = x,
]
coordinates
{
(20,2.8559703)
(300,30.5301677)
(4000,400.3050655)
(50000,5000.1413136)
(600000,60000.0322865)
(7000000,600000.9675052)
(80000000,7000000.9377747)
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
Best Answer
You can use
xticklabel=\pgfmathprintnumber{\tick}\,\%
.xticklabel
defines the code used for printing the tick labels, and\tick
contains the current tick value.