2

EDIT: Added picture to show what it should look like. enter image description here

I'm trying to use pgfplots to plot the interesting part of some SF6 (Sulfur hexafluoride) isotherms.

This is my MWE:

\documentclass{minimal}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xmin=0,
        xmax=0.0015,
        ymin=0,
        ymax=6*10^6,
        ]
        \foreach \i in {25,35,45,50} {\addplot+[no markers, solid, smooth] {8.314*(273.15+\i)/(x-0.00008786)-0.785758865/x^2};}%
    \end{axis}
\end{tikzpicture}

\end{document}

I'm getting the following error:

./root.tex:15: Dimension too large.
<recently read> \pgf@xx 

l.15    \end{axis}

Now I've consulted the 'pgfplots' Manual at http://pgfplots.sourceforge.net/pgfplots.pdf and searched it for my error. Turns out there's a section dedicated to it (2.6.2, p13f) which offers some possible sources. I think it's problem 3:

  1. The axis equal key will be confused if x and y have a very different scale.

But I also can't rule out some of the others and so my question becomes: How do I solve this? I could also generate my plot in Mathematica and import it into my document, but I'd really like to make it 'inline' to ensure consistency and editability.

I'm grateful for all responses & suggestions!

P.S.: This is my first time posting here, so if I haven't provided enough information or something else is wrong with my post, please let me know and I'll be happy to fix it.

3
  • Plotting the function you gave in your specified ranges does not really show something nice to look at (i've done a matlab Simulation). What do you expect the plot to look like? Do you have a reference plot for us? Also the number ranges are quite big. There are negative numbers involved, but maybe some Kind of logarithmic plot would be better?
    – pschulz
    Jan 11 '17 at 16:18
  • Ah, i just read that you are using mathematica. Could you provide us with a plot from mathematica?
    – pschulz
    Jan 11 '17 at 16:20
  • I added a picture to the OP. Jan 11 '17 at 16:24
1

I was not able to reproduce the bug and i tried different versions. Here, however, you have a working example with some cosmetic additions (consider them as suggestion):

% x11names needed for colors
\documentclass[x11names]{scrartcl}

\usepackage{polyglossia}
\setmainlanguage{german}

\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{pgfplots}

\pgfplotsset{
    % most recent feature set of pgfplots
    compat=1.14,
    % some settings for grid
    grid style={black!60!white, thin, densely dotted},
    % modify plot appearance
    every axis plot/.append style={no markers, thick},
    % i like the labels a bit smaller
    label style={font=\small},
    tick label style={font=\small}
}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            [
                grid = both,
                % minor ticks for tighter grid
                minor x tick num = 1,
                minor y tick num = 3,
                xmin = 0,
                xmax = 0.0015,
                ymin = 0,
                ymax = 6e6,
                % you don't need too much samples with the 'smooth' key, so 100 is fine
                samples = 100,
                % don't start at 0 or you will get another crossing line
                domain=0.0001:0.0015,
                % change colors
                cycle list = {DodgerBlue3, OrangeRed2, Green4, DarkGoldenrod3},
                % remove the scaled ticks but scale the axis
                scaled x ticks = manual:{}{\pgfmathparse{#1*1e3}},
                scaled y ticks = manual:{}{\pgfmathparse{#1/1e6}},
                % use appropriate units (milli and mega)
                xlabel = {$V$ [mX]},
                ylabel = {$p$ [MY]}
            ]
            \foreach \T in {25,35,45,50}
            {
                \addplot+[smooth] expression { (8.314 * (273.15 + \T) / (x - 0.00008786)) - 0.785758865 * (1 / (x^2)) };
            }
        \end{axis}
    \end{tikzpicture}
\end{document}

Plot

I haven't really changed your expression, so i can't tell you what was wrong with your example, sorry.

One word about the scaled ticks: i know it's the default with pgfplots, but i really don't like it. I think it's always better to use the right SI prefix (in this case milli or mega), logarithmic axis (not really applicable here) or a different unit, which scales better (dB vs. V, eV vs J etc.) I don't know anything about your plot, so i used the units X and Y.

4
  • Looks awesome! I'll try it as soon as I get back to a computer and report back. Thank you very much for your effort! Jan 11 '17 at 18:16
  • The two most important changes are setting a domain (otherwise you will generate values close to infinity around x = 0) and samples (to provide enough sampling points within the specified domain). With these two changes also the MWE provided in the question will run without errors.
    – hakaze
    Jan 11 '17 at 18:21
  • Yeah i thought so too, but it works for me without these keys, but it looks ugly.
    – pschulz
    Jan 11 '17 at 18:34
  • @pschulz Interesting, I also use pgfplotsversion 1.14 and @samuel-badr's MWE reproducibly throws dimension too large errors. Just adding domain resolves the error message, but produces the "ugly" results, because there are not enough samples between 0.001 and 0.002.
    – hakaze
    Jan 11 '17 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.