LaTeX forum ⇒ Graphics, Figures & TablesBar Chart with small Y-Range Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
doeminick
Posts: 3
Joined: Mon Oct 28, 2013 10:03 pm

Bar Chart with small Y-Range

Postby doeminick » Mon Oct 28, 2013 10:08 pm

Hi!

I would like to create a bar chart graphics for which Im using matlab2tikz to generate my output. That has been working fine untill now. Now I want to create a bar chart with relatively small Y-range (ymin=0.996, ymax=1.002), and I get "Dimension too large" error. I checked the pgfplot manual and it states that actually plots with small absolute range can cause this error. So I tried to simply multiply my data by 1000 and later change the Y-Tickz, but I get the same error, even now ymin=996, ymax=1002.

Can someone help me? Thank you :).
Here is the original tikz code:
  1. % This file was created by matlab2tikz v0.4.1.
  2. % Copyright (c) 2008--2013, Nico Schlömer <nico.schloemer@gmail.com>
  3. % All rights reserved.
  4. %
  5. % The latest updates can be retrieved from
  6. % http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
  7. % where you can also make suggestions and rate matlab2tikz.
  8. %
  9. %
  10. %
  11.  
  12. % defining custom colors
  13. \definecolor{mycolor1}{rgb}{0,0,0.00520833333333333}%
  14.  
  15. \begin{tikzpicture}
  16. \begin{axis}[%
  17. width=\figurewidth,
  18. height=\figureheight,
  19. area legend,
  20. scale only axis,
  21. xmin=0.5,
  22. xmax=4.5,
  23. xtick={1,2,3,4},
  24. xticklabels={A,B,C,D},
  25. ymin=0.996,
  26. ymax=1.002,
  27. ylabel={Verbesserung},
  28. ymajorgrids,
  29. legend style={at={(0.5,1.03)},anchor=south,legend columns=2,draw=black,fill=white,legend cell align=left}
  30. ]
  31. \addplot[ybar,bar width=0.0571428571428571\figurewidth,bar shift=-0.0357142857142857\figurewidth,fill=mycolor1,draw=black] plot coordinates{(1,1)
  32. (2,1)
  33. (3,1)
  34. (4,1)};
  35.  
  36. \addlegendentry{Ohne};
  37.  
  38. \addplot [
  39. color=black,
  40. solid,
  41. forget plot
  42. ]
  43. table[row sep=crcr]{
  44. 0.5 0\\
  45. 4.5 0\\
  46. };
  47. \addplot[ybar,bar width=0.0571428571428571\figurewidth,bar shift=0.0357142857142857\figurewidth,fill=white,draw=black] plot coordinates{(1,1.00063267718012)
  48. (2,1.00016121821389)
  49. (3,1.00108135520258)
  50. (4,0.999543145163719)};
  51.  
  52. \addlegendentry{Mit};
  53.  
  54. \end{axis}
  55. \end{tikzpicture}%

Tags:

User avatar
Johannes_B
Site Moderator
Posts: 4044
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Mon Oct 28, 2013 10:47 pm

Crosspost to GoLaTeX. Please read, what our administrator thinks about that

If you want to plot in the y range of 0.996 to 1.002, why are you plotting somethin like this:

  1. \addplot [
  2. color=black,
  3. solid,
  4. forget plot
  5. ]
  6. table[row sep=crcr]{
  7. 0.5 0\\
  8. 4.5 0\\
  9. };


By the way, your code is not compilable without modifications. Please read about Minimal working examples oder Minimalbeispiele (to see a german explanation).
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

doeminick
Posts: 3
Joined: Mon Oct 28, 2013 10:03 pm

Postby doeminick » Mon Oct 28, 2013 11:22 pm

Im sorry, I didnt check the rule about "crossposts". I just wanted to reach as many people as possible, because I need this graphic soon.
So can somebody anyway help me?

User avatar
Stefan Kottwitz
Site Admin
Posts: 9434
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue Oct 29, 2013 1:31 am

It's just that people would like to know if a question is already discussed somewhere else, to save work if it's alread solved there. A simple hyperlink and all is fine. And as you write in German, there' also the question and answer site http://texwelt.de ;-) cross-posts are very welcome there, because of the goal to build a fine indexed German knowledge database based on questions and answers.

Stefan
Site admin

User avatar
Johannes_B
Site Moderator
Posts: 4044
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Oct 29, 2013 10:00 am

I already told you, that the error is caused by the coordinates forming a line. Comment them out and it compiles.

  1. \documentclass[12pt]{article}
  2. \usepackage{pgfplots}
  3. \begin{document}
  4.  
  5. \newcommand{\figurewidth}{9cm}
  6. \let\figureheight\figurewidth
  7. %this is not the right way to set a length, tough
  8.  
  9.  
  10. % This file was created by matlab2tikz v0.4.1.
  11. % and modified by Johannes_B for www.latex-community.org
  12. % Copyright (c) 2008--2013, Nico Schlömer <nico.schloemer@gmail.com>
  13. % All rights reserved.
  14. %
  15. % The latest updates can be retrieved from
  16. % http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
  17. % where you can also make suggestions and rate matlab2tikz.
  18. %
  19. %
  20. %
  21.  
  22. % defining custom colors
  23. \definecolor{mycolor1}{rgb}{0,0,0.00520833333333333}%
  24.  
  25. \begin{tikzpicture}
  26. \begin{axis}[%
  27. yticklabel style={/pgf/number format/fixed,
  28. /pgf/number format/precision=3},
  29. width=\figurewidth,
  30. height=\figureheight,
  31. %area legend,
  32. %scale only axis,
  33. %xmin=0.5,
  34. %xmax=4.5,
  35. xtick={1,2,3,4},
  36. xticklabels={A,B,C,D},
  37. ymin=0.996,
  38. ymax=1.002,
  39. ylabel={Verbesserung},
  40. %ymajorgrids,
  41. legend style={at={(0.5,1.03)},anchor=south,legend columns=2,draw=black,fill=white,legend cell align=left},
  42. ]
  43. \addplot[ybar,%bar width=0.0571428571428571\figurewidth,bar shift=-0.0357142857142857\figurewidth,
  44. fill=mycolor1,draw=black] plot coordinates{(1,1)
  45. (2,1)
  46. (3,1)
  47. (4,1)};
  48. \addlegendentry{Ohne};
  49.  
  50. %\addplot [
  51. %color=black,
  52. %solid,
  53. %forget plot
  54. %]
  55. %table[row sep=crcr]{
  56. %0.5 0\\
  57. %4.5 0\\
  58. %};
  59.  
  60. \addplot[ybar,%bar width=0.0571428571428571\figurewidth,bar shift=0.0357142857142857\figurewidth,
  61. bar shift=.3\figurewidth,
  62. fill=white,draw=black] plot coordinates{(1,1.00063267718012)
  63. (2,1.00016121821389)
  64. (3,1.00108135520258)
  65. (4,0.999543145163719)};
  66. \addlegendentry{Mit};
  67.  
  68. \end{axis}
  69. \end{tikzpicture}%
  70. \end{document}


In the last few days, many people weren't satisfied with the output of "matlab2tikz.m". The pgfplots package is a very powerful tool. You can export your data as ASCII files and plot it without the intermediate matlab2tikz export. Modifying the looks is much easier this way.

Best regards
Johannes
Last edited by Johannes_B on Tue Oct 29, 2013 12:23 pm, edited 1 time in total.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

doeminick
Posts: 3
Joined: Mon Oct 28, 2013 10:03 pm

Postby doeminick » Tue Oct 29, 2013 12:21 pm

Thank you very much for this reply. I am not very familiar, or better to be said not at all few days ago with tikz, thats why I always used this little Matlab-script. I guess Ill try to switch from now on.

Greetings


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 5 guests