LaTeX forum ⇒ Graphics, Figures & TablesRound Precision for Axis Labels

Information and discussion about graphics, figures & tables in LaTeX documents.
computernormal
Posts: 3
Joined: Tue Aug 27, 2013 1:01 am

Round Precision for Axis Labels

Postby computernormal » Fri Sep 06, 2013 5:04 pm

Hello,

how can I prevent, that the values on my axis were rounded on two digits after point? I need three digits after the point.

  1. \begin{tikzpicture}
  2. \begin{axis}[
  3. legend pos=outer north east,
  4. grid=major,
  5. xlabel=$t\;in\;ms$,
  6. ytick={-0.625,-0.5,-0.375,-0.25,-0.125,0,0.125,0.25,0.375,0.5,0.625},
  7. ylabel=$U\;in\;Volt$, xmin=0,
  8. ]
  9. \addplot[smooth,color=blue,mark=none] coordinates {
  10. (0,-0.5)
  11. (3,-0.5)
  12. };
  13. \addplot[smooth,color=blue,mark=none] coordinates {
  14. (0,-0.375)
  15. (3,-0.375)
  16. };
  17. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  18. (0,-0.25)
  19. (3,-0.25)
  20. };
  21. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  22. (0,-0.125)
  23. (3,-0.125)
  24. };
  25. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  26. (0,0)
  27. (3,0)
  28. };
  29. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  30. (0,0.125)
  31. (3,0.125)
  32. };
  33. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  34. (0,0.25)
  35. (3,0.25)
  36. };
  37. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  38. (0,0.375)
  39. (3,0.375)
  40. };
  41. \addplot[smooth,color=blue,mark=none,fill opacity=.2] coordinates {
  42. (0,0.5)
  43. (3,0.5)
  44. };
  45. \addplot[smooth,color=red,mark=x] coordinates {
  46. (0,0)
  47. };
  48. \addplot[smooth,color=red,mark=x] coordinates {
  49. (0.2,0)
  50. (0.2,0.4)
  51. };
  52. \addplot[smooth,color=red,mark=x] coordinates {
  53. (0.4,0)
  54. (0.4,0.458)
  55. };
  56. \addplot[smooth,color=red,mark=x] coordinates {
  57. (0.6,0)
  58. (0.6,-0.08)
  59. };
  60. \addplot[smooth,color=red,mark=x] coordinates {
  61. (0.8,0)
  62. (0.8,-0.447)
  63. };
  64. \addplot[smooth,color=red,mark=x] coordinates {
  65. (1,0)
  66. (1,0)
  67. };
  68. \addplot[smooth,color=red,mark=x] coordinates {
  69. (1.2,0)
  70. (1.2,0.4)
  71. };
  72. \addplot[smooth,color=red,mark=x] coordinates {
  73. (1.4,0)
  74. (1.4,0.33)
  75. };
  76. \addplot[smooth,color=red,mark=x] coordinates {
  77. (1.6,0)
  78. (1.6,0)
  79. };
  80. \addplot[smooth,color=red,mark=x] coordinates {
  81. (1.8,0)
  82. (1.8,-0.325)
  83. };
  84. \addplot[smooth,color=red,mark=x] coordinates {
  85. (2,0)
  86. (2,-0)
  87. };
  88. \addplot[smooth,color=red,mark=x] coordinates {
  89. (2.2,0)
  90. (2.2,0.435)
  91. };
  92. \addplot[smooth,color=red,mark=x] coordinates {
  93. (2.4,0)
  94. (2.4,0.335)
  95. };
  96. \addplot[smooth,color=red,mark=x] coordinates {
  97. (2.6,0)
  98. (2.6,-0.1)
  99. };
  100. \addplot[smooth,color=red,mark=x] coordinates {
  101. (2.8,0)
  102. (2.8,-0.48)
  103. };
  104. \addplot[smooth,color=red,mark=x] coordinates {
  105. (3,0)
  106. (3,0)
  107. };
  108. \legend{$f[t]$};
  109. \end{axis}
  110. \end{tikzpicture}



greetz andre

Tags:

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Fri Sep 06, 2013 6:51 pm

You need to explicitly specify the number format for the ticks by the yticklabel style key. Furthermore I ventured to shorten your example by making it a comb plot in y direction and completed it to make it compilable. For details please refer to the pgfplots manual. The output is attached.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{pgfplots}
  4.  
  5. \pgfplotsset{
  6. compat=newest,
  7. major grid style=blue,
  8. xlabel near ticks,
  9. ylabel near ticks
  10. }
  11.  
  12. \begin{document}
  13. \begin{tikzpicture}
  14. \begin{axis}[
  15. legend pos=outer north east,
  16. xmin=0,
  17. xmax=3,
  18. xlabel={$t$ / ms},
  19. ymajorgrids=true,
  20. ymin=-0.625,
  21. ymax=0.625,
  22. ytick={-0.625,-0.5,...,0.625},
  23. yticklabel style={/pgf/number format/.cd,fixed,precision=3},
  24. ylabel={$U$ / V}
  25. ]
  26. \addplot[ycomb,color=red,mark=x] coordinates {
  27. (0,0)
  28. (0.2,0.4)
  29. (0.4,0.458)
  30. (0.6,-0.08)
  31. (0.8,-0.447)
  32. (1,0)
  33. (1.2,0.4)
  34. (1.4,0.33)
  35. (1.6,0)
  36. (1.8,-0.325)
  37. (2,0)
  38. (2.2,0.435)
  39. (2.4,0.335)
  40. (2.6,-0.1)
  41. (2.8,-0.48)
  42. (3,0)
  43. };
  44. \legend{$f[t]$};
  45. \end{axis}
  46. \end{tikzpicture}
  47. \end{document}


Remarks:

  • For physical quantities you may look at the siunitx package.


Thorsten
Attachments
otmp.png
otmp.png (4.87 KiB) Viewed 2605 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests