Plot data from external file with floating numbers












3















I found yesterday this beautiful simple code:



documentclass{article}
usepackage{pgfplotstable}
usepackage{pgfplots}
pagestyle{empty}
begin{document}

%pgfplotstabletypeset{data.dat}

vspace{1cm}

begin{tikzpicture}
begin{axis}[
xlabel=Q Series,
ylabel=P Values]
addplot table [y=P, x=$Q_A$]{data.dat};
addlegendentry{$Q_A$ series}
addplot table [y=P, x=$Q_B$]{data.dat};
addlegendentry{$Q_B$ series}
addplot table [y=P, x=$Q_D$]{data.dat};
addlegendentry{$Q_D$ series}
end{axis}
end{tikzpicture}

end{document}


which works well with the external file



P $Q_A$ $Q_B$ $Q_D$
10 5 7 12
8 8 10 18
6 12 16 28


Yet, if I have more comlicated numbers in the file, for example



P $Q_A$ $Q_B$ $Q_D$
10 14.2*10^2 7 12
8 8 10 18
6 12 16 28


the code crashes.



How do I have to adapt the code or data to work?



Thx in advance










share|improve this question

























  • I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

    – JouleV
    Apr 20 at 10:13











  • So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

    – Andreas
    Apr 20 at 11:02













  • You can do that of course, but I can't be sure whether it would be the best option.

    – JouleV
    Apr 20 at 11:03
















3















I found yesterday this beautiful simple code:



documentclass{article}
usepackage{pgfplotstable}
usepackage{pgfplots}
pagestyle{empty}
begin{document}

%pgfplotstabletypeset{data.dat}

vspace{1cm}

begin{tikzpicture}
begin{axis}[
xlabel=Q Series,
ylabel=P Values]
addplot table [y=P, x=$Q_A$]{data.dat};
addlegendentry{$Q_A$ series}
addplot table [y=P, x=$Q_B$]{data.dat};
addlegendentry{$Q_B$ series}
addplot table [y=P, x=$Q_D$]{data.dat};
addlegendentry{$Q_D$ series}
end{axis}
end{tikzpicture}

end{document}


which works well with the external file



P $Q_A$ $Q_B$ $Q_D$
10 5 7 12
8 8 10 18
6 12 16 28


Yet, if I have more comlicated numbers in the file, for example



P $Q_A$ $Q_B$ $Q_D$
10 14.2*10^2 7 12
8 8 10 18
6 12 16 28


the code crashes.



How do I have to adapt the code or data to work?



Thx in advance










share|improve this question

























  • I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

    – JouleV
    Apr 20 at 10:13











  • So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

    – Andreas
    Apr 20 at 11:02













  • You can do that of course, but I can't be sure whether it would be the best option.

    – JouleV
    Apr 20 at 11:03














3












3








3








I found yesterday this beautiful simple code:



documentclass{article}
usepackage{pgfplotstable}
usepackage{pgfplots}
pagestyle{empty}
begin{document}

%pgfplotstabletypeset{data.dat}

vspace{1cm}

begin{tikzpicture}
begin{axis}[
xlabel=Q Series,
ylabel=P Values]
addplot table [y=P, x=$Q_A$]{data.dat};
addlegendentry{$Q_A$ series}
addplot table [y=P, x=$Q_B$]{data.dat};
addlegendentry{$Q_B$ series}
addplot table [y=P, x=$Q_D$]{data.dat};
addlegendentry{$Q_D$ series}
end{axis}
end{tikzpicture}

end{document}


which works well with the external file



P $Q_A$ $Q_B$ $Q_D$
10 5 7 12
8 8 10 18
6 12 16 28


Yet, if I have more comlicated numbers in the file, for example



P $Q_A$ $Q_B$ $Q_D$
10 14.2*10^2 7 12
8 8 10 18
6 12 16 28


the code crashes.



How do I have to adapt the code or data to work?



Thx in advance










share|improve this question
















I found yesterday this beautiful simple code:



documentclass{article}
usepackage{pgfplotstable}
usepackage{pgfplots}
pagestyle{empty}
begin{document}

%pgfplotstabletypeset{data.dat}

vspace{1cm}

begin{tikzpicture}
begin{axis}[
xlabel=Q Series,
ylabel=P Values]
addplot table [y=P, x=$Q_A$]{data.dat};
addlegendentry{$Q_A$ series}
addplot table [y=P, x=$Q_B$]{data.dat};
addlegendentry{$Q_B$ series}
addplot table [y=P, x=$Q_D$]{data.dat};
addlegendentry{$Q_D$ series}
end{axis}
end{tikzpicture}

end{document}


which works well with the external file



P $Q_A$ $Q_B$ $Q_D$
10 5 7 12
8 8 10 18
6 12 16 28


Yet, if I have more comlicated numbers in the file, for example



P $Q_A$ $Q_B$ $Q_D$
10 14.2*10^2 7 12
8 8 10 18
6 12 16 28


the code crashes.



How do I have to adapt the code or data to work?



Thx in advance







pgfplotstable external-files






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 20 at 10:06









JouleV

15.6k22667




15.6k22667










asked Apr 20 at 10:04









AndreasAndreas

384




384













  • I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

    – JouleV
    Apr 20 at 10:13











  • So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

    – Andreas
    Apr 20 at 11:02













  • You can do that of course, but I can't be sure whether it would be the best option.

    – JouleV
    Apr 20 at 11:03



















  • I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

    – JouleV
    Apr 20 at 10:13











  • So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

    – Andreas
    Apr 20 at 11:02













  • You can do that of course, but I can't be sure whether it would be the best option.

    – JouleV
    Apr 20 at 11:03

















I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

– JouleV
Apr 20 at 10:13





I think the purpose of reading external files is that those external files are generated by a script that can not contain any "uncalculated" numbers.

– JouleV
Apr 20 at 10:13













So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

– Andreas
Apr 20 at 11:02







So my best bet is just writing the number in full? Speicifically 1,3*10^5 -> 1300000.

– Andreas
Apr 20 at 11:02















You can do that of course, but I can't be sure whether it would be the best option.

– JouleV
Apr 20 at 11:03





You can do that of course, but I can't be sure whether it would be the best option.

– JouleV
Apr 20 at 11:03










3 Answers
3






active

oldest

votes


















3














You can replace *10^ by e



P $Q_A$ $Q_B$ $Q_D$
10 14.2e2 7 12
8 8 10 18
6 12 16 28





share|improve this answer































    3














    You can load the data in a macro and then preprocess the data. I'm assuming here that your values are in a format the fpeval from expl3/xfp can handle (but your example value is rather large compared to the rest, so the plot looks odd):



    documentclass{article}
    usepackage{pgfplotstable}
    usepackage{pgfplots,xfp}
    pagestyle{empty}
    begin{document}

    pgfplotstableread{data.dat}{data}
    pgfplotstablecreatecol[create col/expr={fpeval{thisrow{$Q_A$}}}]{$Q_A$}data
    vspace{1cm}

    begin{tikzpicture}
    begin{axis}[
    xlabel=Q Series,
    ylabel=P Values]
    addplot table [y=P, x=$Q_A$]{data};
    addlegendentry{$Q_A$ series}
    addplot table [y=P, x=$Q_B$]{data};
    addlegendentry{$Q_B$ series}
    addplot table [y=P, x=$Q_D$]{data};
    addlegendentry{$Q_D$ series}
    end{axis}
    end{tikzpicture}

    end{document}


    enter image description here






    share|improve this answer































      0














      You only need to tell pgfplots that these are expressions. That is, instead of



      addplot table [y=P, x=$Q_A$]{data.dat};


      you only need



      addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};


      MWE:



      documentclass{article}
      usepackage{filecontents}
      begin{filecontents*}{data.dat}
      P $Q_A$ $Q_B$ $Q_D$
      10 14.2*10^2 7 12
      8 8 10 18
      6 12 16 28
      end{filecontents*}
      %usepackage{pgfplotstable}
      usepackage{pgfplots}
      pgfplotsset{compat=1.16}
      pagestyle{empty}
      begin{document}

      %pgfplotstabletypeset{data.dat}

      vspace{1cm}

      begin{tikzpicture}
      begin{axis}[
      xlabel=Q Series,
      ylabel=P Values]
      addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};
      addlegendentry{$Q_A$ series}
      addplot table [y=P, x expr=thisrow{$Q_B$}]{data.dat};
      addlegendentry{$Q_B$ series}
      addplot table [y=P, x expr=thisrow{$Q_D$}]{data.dat};
      addlegendentry{$Q_D$ series}
      end{axis}
      end{tikzpicture}
      end{document}


      enter image description here






      share|improve this answer
























        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "85"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f485720%2fplot-data-from-external-file-with-floating-numbers%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        3














        You can replace *10^ by e



        P $Q_A$ $Q_B$ $Q_D$
        10 14.2e2 7 12
        8 8 10 18
        6 12 16 28





        share|improve this answer




























          3














          You can replace *10^ by e



          P $Q_A$ $Q_B$ $Q_D$
          10 14.2e2 7 12
          8 8 10 18
          6 12 16 28





          share|improve this answer


























            3












            3








            3







            You can replace *10^ by e



            P $Q_A$ $Q_B$ $Q_D$
            10 14.2e2 7 12
            8 8 10 18
            6 12 16 28





            share|improve this answer













            You can replace *10^ by e



            P $Q_A$ $Q_B$ $Q_D$
            10 14.2e2 7 12
            8 8 10 18
            6 12 16 28






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 20 at 11:07









            David CarlisleDavid Carlisle

            501k4211471897




            501k4211471897























                3














                You can load the data in a macro and then preprocess the data. I'm assuming here that your values are in a format the fpeval from expl3/xfp can handle (but your example value is rather large compared to the rest, so the plot looks odd):



                documentclass{article}
                usepackage{pgfplotstable}
                usepackage{pgfplots,xfp}
                pagestyle{empty}
                begin{document}

                pgfplotstableread{data.dat}{data}
                pgfplotstablecreatecol[create col/expr={fpeval{thisrow{$Q_A$}}}]{$Q_A$}data
                vspace{1cm}

                begin{tikzpicture}
                begin{axis}[
                xlabel=Q Series,
                ylabel=P Values]
                addplot table [y=P, x=$Q_A$]{data};
                addlegendentry{$Q_A$ series}
                addplot table [y=P, x=$Q_B$]{data};
                addlegendentry{$Q_B$ series}
                addplot table [y=P, x=$Q_D$]{data};
                addlegendentry{$Q_D$ series}
                end{axis}
                end{tikzpicture}

                end{document}


                enter image description here






                share|improve this answer




























                  3














                  You can load the data in a macro and then preprocess the data. I'm assuming here that your values are in a format the fpeval from expl3/xfp can handle (but your example value is rather large compared to the rest, so the plot looks odd):



                  documentclass{article}
                  usepackage{pgfplotstable}
                  usepackage{pgfplots,xfp}
                  pagestyle{empty}
                  begin{document}

                  pgfplotstableread{data.dat}{data}
                  pgfplotstablecreatecol[create col/expr={fpeval{thisrow{$Q_A$}}}]{$Q_A$}data
                  vspace{1cm}

                  begin{tikzpicture}
                  begin{axis}[
                  xlabel=Q Series,
                  ylabel=P Values]
                  addplot table [y=P, x=$Q_A$]{data};
                  addlegendentry{$Q_A$ series}
                  addplot table [y=P, x=$Q_B$]{data};
                  addlegendentry{$Q_B$ series}
                  addplot table [y=P, x=$Q_D$]{data};
                  addlegendentry{$Q_D$ series}
                  end{axis}
                  end{tikzpicture}

                  end{document}


                  enter image description here






                  share|improve this answer


























                    3












                    3








                    3







                    You can load the data in a macro and then preprocess the data. I'm assuming here that your values are in a format the fpeval from expl3/xfp can handle (but your example value is rather large compared to the rest, so the plot looks odd):



                    documentclass{article}
                    usepackage{pgfplotstable}
                    usepackage{pgfplots,xfp}
                    pagestyle{empty}
                    begin{document}

                    pgfplotstableread{data.dat}{data}
                    pgfplotstablecreatecol[create col/expr={fpeval{thisrow{$Q_A$}}}]{$Q_A$}data
                    vspace{1cm}

                    begin{tikzpicture}
                    begin{axis}[
                    xlabel=Q Series,
                    ylabel=P Values]
                    addplot table [y=P, x=$Q_A$]{data};
                    addlegendentry{$Q_A$ series}
                    addplot table [y=P, x=$Q_B$]{data};
                    addlegendentry{$Q_B$ series}
                    addplot table [y=P, x=$Q_D$]{data};
                    addlegendentry{$Q_D$ series}
                    end{axis}
                    end{tikzpicture}

                    end{document}


                    enter image description here






                    share|improve this answer













                    You can load the data in a macro and then preprocess the data. I'm assuming here that your values are in a format the fpeval from expl3/xfp can handle (but your example value is rather large compared to the rest, so the plot looks odd):



                    documentclass{article}
                    usepackage{pgfplotstable}
                    usepackage{pgfplots,xfp}
                    pagestyle{empty}
                    begin{document}

                    pgfplotstableread{data.dat}{data}
                    pgfplotstablecreatecol[create col/expr={fpeval{thisrow{$Q_A$}}}]{$Q_A$}data
                    vspace{1cm}

                    begin{tikzpicture}
                    begin{axis}[
                    xlabel=Q Series,
                    ylabel=P Values]
                    addplot table [y=P, x=$Q_A$]{data};
                    addlegendentry{$Q_A$ series}
                    addplot table [y=P, x=$Q_B$]{data};
                    addlegendentry{$Q_B$ series}
                    addplot table [y=P, x=$Q_D$]{data};
                    addlegendentry{$Q_D$ series}
                    end{axis}
                    end{tikzpicture}

                    end{document}


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 20 at 12:59









                    Ulrike FischerUlrike Fischer

                    201k9308695




                    201k9308695























                        0














                        You only need to tell pgfplots that these are expressions. That is, instead of



                        addplot table [y=P, x=$Q_A$]{data.dat};


                        you only need



                        addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};


                        MWE:



                        documentclass{article}
                        usepackage{filecontents}
                        begin{filecontents*}{data.dat}
                        P $Q_A$ $Q_B$ $Q_D$
                        10 14.2*10^2 7 12
                        8 8 10 18
                        6 12 16 28
                        end{filecontents*}
                        %usepackage{pgfplotstable}
                        usepackage{pgfplots}
                        pgfplotsset{compat=1.16}
                        pagestyle{empty}
                        begin{document}

                        %pgfplotstabletypeset{data.dat}

                        vspace{1cm}

                        begin{tikzpicture}
                        begin{axis}[
                        xlabel=Q Series,
                        ylabel=P Values]
                        addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};
                        addlegendentry{$Q_A$ series}
                        addplot table [y=P, x expr=thisrow{$Q_B$}]{data.dat};
                        addlegendentry{$Q_B$ series}
                        addplot table [y=P, x expr=thisrow{$Q_D$}]{data.dat};
                        addlegendentry{$Q_D$ series}
                        end{axis}
                        end{tikzpicture}
                        end{document}


                        enter image description here






                        share|improve this answer




























                          0














                          You only need to tell pgfplots that these are expressions. That is, instead of



                          addplot table [y=P, x=$Q_A$]{data.dat};


                          you only need



                          addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};


                          MWE:



                          documentclass{article}
                          usepackage{filecontents}
                          begin{filecontents*}{data.dat}
                          P $Q_A$ $Q_B$ $Q_D$
                          10 14.2*10^2 7 12
                          8 8 10 18
                          6 12 16 28
                          end{filecontents*}
                          %usepackage{pgfplotstable}
                          usepackage{pgfplots}
                          pgfplotsset{compat=1.16}
                          pagestyle{empty}
                          begin{document}

                          %pgfplotstabletypeset{data.dat}

                          vspace{1cm}

                          begin{tikzpicture}
                          begin{axis}[
                          xlabel=Q Series,
                          ylabel=P Values]
                          addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};
                          addlegendentry{$Q_A$ series}
                          addplot table [y=P, x expr=thisrow{$Q_B$}]{data.dat};
                          addlegendentry{$Q_B$ series}
                          addplot table [y=P, x expr=thisrow{$Q_D$}]{data.dat};
                          addlegendentry{$Q_D$ series}
                          end{axis}
                          end{tikzpicture}
                          end{document}


                          enter image description here






                          share|improve this answer


























                            0












                            0








                            0







                            You only need to tell pgfplots that these are expressions. That is, instead of



                            addplot table [y=P, x=$Q_A$]{data.dat};


                            you only need



                            addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};


                            MWE:



                            documentclass{article}
                            usepackage{filecontents}
                            begin{filecontents*}{data.dat}
                            P $Q_A$ $Q_B$ $Q_D$
                            10 14.2*10^2 7 12
                            8 8 10 18
                            6 12 16 28
                            end{filecontents*}
                            %usepackage{pgfplotstable}
                            usepackage{pgfplots}
                            pgfplotsset{compat=1.16}
                            pagestyle{empty}
                            begin{document}

                            %pgfplotstabletypeset{data.dat}

                            vspace{1cm}

                            begin{tikzpicture}
                            begin{axis}[
                            xlabel=Q Series,
                            ylabel=P Values]
                            addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};
                            addlegendentry{$Q_A$ series}
                            addplot table [y=P, x expr=thisrow{$Q_B$}]{data.dat};
                            addlegendentry{$Q_B$ series}
                            addplot table [y=P, x expr=thisrow{$Q_D$}]{data.dat};
                            addlegendentry{$Q_D$ series}
                            end{axis}
                            end{tikzpicture}
                            end{document}


                            enter image description here






                            share|improve this answer













                            You only need to tell pgfplots that these are expressions. That is, instead of



                            addplot table [y=P, x=$Q_A$]{data.dat};


                            you only need



                            addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};


                            MWE:



                            documentclass{article}
                            usepackage{filecontents}
                            begin{filecontents*}{data.dat}
                            P $Q_A$ $Q_B$ $Q_D$
                            10 14.2*10^2 7 12
                            8 8 10 18
                            6 12 16 28
                            end{filecontents*}
                            %usepackage{pgfplotstable}
                            usepackage{pgfplots}
                            pgfplotsset{compat=1.16}
                            pagestyle{empty}
                            begin{document}

                            %pgfplotstabletypeset{data.dat}

                            vspace{1cm}

                            begin{tikzpicture}
                            begin{axis}[
                            xlabel=Q Series,
                            ylabel=P Values]
                            addplot table [y=P, x expr=thisrow{$Q_A$}]{data.dat};
                            addlegendentry{$Q_A$ series}
                            addplot table [y=P, x expr=thisrow{$Q_B$}]{data.dat};
                            addlegendentry{$Q_B$ series}
                            addplot table [y=P, x expr=thisrow{$Q_D$}]{data.dat};
                            addlegendentry{$Q_D$ series}
                            end{axis}
                            end{tikzpicture}
                            end{document}


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 21 at 1:06









                            marmotmarmot

                            121k6158296




                            121k6158296






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f485720%2fplot-data-from-external-file-with-floating-numbers%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Plaza Victoria

                                Puebla de Zaragoza

                                Musa