## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Bar 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

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:
% This file was created by matlab2tikz v0.4.1.% Copyright (c) 2008--2013, Nico Schlömer <nico.schloemer@gmail.com>% All rights reserved.% % The latest updates can be retrieved from%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz% where you can also make suggestions and rate matlab2tikz.% % %  % defining custom colors\definecolor{mycolor1}{rgb}{0,0,0.00520833333333333}% \begin{tikzpicture}\begin{axis}[%width=\figurewidth,height=\figureheight,area legend,scale only axis,xmin=0.5,xmax=4.5,xtick={1,2,3,4},xticklabels={A,B,C,D},ymin=0.996,ymax=1.002,ylabel={Verbesserung},ymajorgrids,legend style={at={(0.5,1.03)},anchor=south,legend columns=2,draw=black,fill=white,legend cell align=left}]\addplot[ybar,bar width=0.0571428571428571\figurewidth,bar shift=-0.0357142857142857\figurewidth,fill=mycolor1,draw=black] plot coordinates{(1,1)(2,1)(3,1)(4,1)}; \addlegendentry{Ohne}; \addplot [color=black,solid,forget plot]table[row sep=crcr]{0.5 0\\4.5 0\\};\addplot[ybar,bar width=0.0571428571428571\figurewidth,bar shift=0.0357142857142857\figurewidth,fill=white,draw=black] plot coordinates{(1,1.00063267718012)(2,1.00016121821389)(3,1.00108135520258)(4,0.999543145163719)}; \addlegendentry{Mit}; \end{axis}\end{tikzpicture}%

Tags:

Johannes_B
Site Moderator
Posts: 4116
Joined: Thu Nov 01, 2012 4:08 pm

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

\addplot [color=black,solid,forget plot]table[row sep=crcr]{0.5 0\\4.5 0\\};

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

Stefan Kottwitz
Posts: 9557
Joined: Mon Mar 10, 2008 9:44 pm
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

Johannes_B
Site Moderator
Posts: 4116
Joined: Thu Nov 01, 2012 4:08 pm
I already told you, that the error is caused by the coordinates forming a line. Comment them out and it compiles.

\documentclass[12pt]{article}\usepackage{pgfplots}\begin{document} \newcommand{\figurewidth}{9cm}\let\figureheight\figurewidth%this is not the right way to set a length, tough  % This file was created by matlab2tikz v0.4.1. % and modified by Johannes_B for www.latex-community.org% Copyright (c) 2008--2013, Nico Schlömer <nico.schloemer@gmail.com>% All rights reserved.% % The latest updates can be retrieved from%   http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz% where you can also make suggestions and rate matlab2tikz.% % %  % defining custom colors\definecolor{mycolor1}{rgb}{0,0,0.00520833333333333}% \begin{tikzpicture}\begin{axis}[%yticklabel style={/pgf/number format/fixed,                   /pgf/number format/precision=3},width=\figurewidth,height=\figureheight,%area legend,%scale only axis,%xmin=0.5,%xmax=4.5,xtick={1,2,3,4},xticklabels={A,B,C,D},ymin=0.996,ymax=1.002,ylabel={Verbesserung},%ymajorgrids,legend style={at={(0.5,1.03)},anchor=south,legend columns=2,draw=black,fill=white,legend cell align=left},]\addplot[ybar,%bar width=0.0571428571428571\figurewidth,bar shift=-0.0357142857142857\figurewidth,fill=mycolor1,draw=black] plot coordinates{(1,1)(2,1)(3,1)(4,1)};\addlegendentry{Ohne}; %\addplot [%color=black,%solid,%forget plot%]%table[row sep=crcr]{%0.5 0\\%4.5 0\\%}; \addplot[ybar,%bar width=0.0571428571428571\figurewidth,bar shift=0.0357142857142857\figurewidth,bar shift=.3\figurewidth,fill=white,draw=black] plot coordinates{(1,1.00063267718012)(2,1.00016121821389)(3,1.00108135520258)(4,0.999543145163719)};\addlegendentry{Mit}; \end{axis}\end{tikzpicture}%\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
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