TransWikia.com

Dimension too large for a simple cubic formula

TeX - LaTeX Asked by Minh Nghĩa on January 16, 2021

This is the plot I’m working on:

documentclass{book}
usepackage{pgfplots}

begin{document}
begin{tikzpicture}
    begin{axis}[
        axis lines=center,
        samples=200,
        xlabel={(x)},
        xmin=-0.5,xmax=3.5,
        ylabel={(y)},
        ymin=-0.5,ymax=2.5,
    ]
        addplot [green] {(x - 2)^3 + 1};
    end{axis}
end{tikzpicture}
end{document}

If I use ymin=-1.5 or any negative value smaller than -1, the plot renders just fine. However, it complains that Dimension too large when I use ymin=-0.5 as above.

I read the pgfplots docs, section 2.6.2, and still can’t find the solution.

One Answer

If you use default domain, i.e. domain=-5:5, than values of your function seems become becomes to big. This is somehow odd, see @ Torbjørn T. 1 comment.

To resolve this, you have two option:

  • define domain between xmin and xmax (it has not sense to use wider domain), or
  • define restriction for y (function) values:
documentclass{book}
usepackage{pgfplots}
pgfplotsset{compat=1.17}

begin{document}
begin{tikzpicture}
    begin{axis}[
        axis lines=center,
        xlabel={(x)},
        xmin=-0.5,xmax=3.5,
        ylabel={(y)},
        ymin=-0.5,ymax=2.5,
        samples=200,
        restrict y to domain=-0.5:12,
        domain=-0.5:3.5,        
every axis plot post/.append style={very thick},        
    no marks
    ]
        addplot    {(x - 2)^3 + 1};
    end{axis}
end{tikzpicture}
end{document}

second case:

documentclass{book}
usepackage{pgfplots}
pgfplotsset{compat=1.17}

begin{document}
begin{tikzpicture}
    begin{axis}[
        axis lines=center,
        xlabel={(x)},
        xmin=-0.5,xmax=3.5,
        ylabel={(y)},
        ymin=-0.5,ymax=2.5,
        samples=200,
        restrict y to domain=-0.5:12,
every axis plot post/.append style={very thick},        
    no marks
    ]
        addplot    {(x - 2)^3 + 1};
    end{axis}
end{tikzpicture}
end{document}

in the both cases the result is the same.

enter image description here

Correct answer by Zarko on January 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP