0

I tried many solutions which were about similar question, but nothing helped... I have a bar chart in Latex, which contains values from 2 550 to 18 016. I want to have numbers on y axis: 0, 5 000, 10 000, 15 000, 20 000. But I have problem, that instead of 20 000 there is strange number 16 384 (I want to have 20 000 there) and also 10^4 (I dont want to see this number). Is there any easy solution for this? My current code is:

    \begin{axis}[
title = Počet matchupov,
ybar,
nodes near coords, bar width=0.4cm,
symbolic x coords={PvZ, TvZ, PvT, TvT, PvP, ZvZ},
yticklabel = {\pgfmathparse{\tick*10000}\pgfmathprintnumber{\pgfmathresult}},  y grid style={dashed,black!60},
        ymajorticks=true,
        ymin=0, ymax=20000,
        ytick style={black},]
\addplot coordinates{(PvZ, 18016)(TvZ, 14531)(PvT, 17385)(TvT, 2550)(PvP, 7015)(ZvZ, 6149)};
    \end{axis}
\end{tikzpicture}

My bar chart currently looks like this

1 Answers1

1

Welcome to this site. If you want answers, you have to post an MME that starts with \documentclass{...} and ends with \end{document}

In the PGFPLOTS manual (version 1.18.1) the section 4.15.3 Tick Scaling – Common Factors In Ticks, we can see :

/pgfplots/scaled ticks=true|false|base 10:<e>|real:<num>|manual:{<label>}{<hcode<} (initially true)
  • With scaled ticks=false your problem is solved.
  • With \pgfkeys{/pgf/number format/set thousands separator={\ }} for space as thousands separator

The code

\documentclass[border=3mm]{standalone}
%https://tex.stackexchange.com/questions/697223/how-to-set-max-of-y-axis-on-bar-chart
\usepackage{pgfplots}

\begin{document} \begin{tikzpicture} \pgfkeys{/pgf/number format/set thousands separator={\ }}%<-- this line \begin{axis}[ scaled ticks=false,%<--- this line title = Počet matchupov, ybar, nodes near coords, bar width=0.4cm, symbolic x coords={PvZ, TvZ, PvT, TvT, PvP, ZvZ}, y grid style={dashed,black!60}, ymajorticks=true, ymin=0, ymax=20000, ytick style={black},] \addplot coordinates{(PvZ, 18016)(TvZ, 14531)(PvT, 17385)(TvT, 2550)(PvP, 7015)(ZvZ, 6149)}; \end{axis} \end{tikzpicture} \end{document}

enter image description here

Zarko
  • 296,517
pascal974
  • 4,652
  • Nice answer (+1)! I took a liberty and correct mark-up of codes in text as well correct some spelling error. If you not liked this, you may revert answer in original form – Zarko Sep 30 '23 at 12:07
  • @Zarko Thank you twice, for your comment and for making the corrections. – pascal974 Sep 30 '23 at 12:20