3

I have a .csv with 2-dimensional data. Now I am trying to plot it in different index ranging from -n:1:n (this index is y-axis).

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}

\pgfplotstableread{
T3,v11
0,0.66582
0.000125,0.66582
0.00025,0.66582
0.000375,0.66582
0.0005,0.66582
0.000625,0.66582
0.00075,0.66582
0.000875,0.66582
0.001,0.66582
0.001125,0.66582
}\dummydata
\begin{axis}[
    domain=-4:4,
    samples y=0, ytick={1,...,4},
]
{
    \addplot3 table [x =T3, y expr=1, z=v11, col sep = comma]
      {\dummydata};
}
\end{axis}
\end{tikzpicture}
\end{document}

This throws errors like:

! Package pgfplots Error: The requested list entry with index 1 of \dummydata i s too large; this list has not enough elements..

See the pgfplots package documentation for explanation. Type H for immediate help. ...

                                               l.27       {\dummydata};
                     This error message was generated by an \errmessage command, so I can't give any explicit help. Pretend that

you're Hercule Poirot: Examine all clues, and deduce the truth by order and method.

! Package pgfplots Error: Sorry, could not retrieve column 'T3' from table ''. Please check spelling (or introduce name aliases)..

See the pgfplots package documentation for explanation. Type H for immediate help. ...

                                               l.27       {\dummydata};
                     (That was another \errmessage.)

! Package pgfplots Error: Sorry, could not retrieve column 'v11' from table ''. Please check spelling (or introduce name aliases)..

See the pgfplots package documentation for explanation. Type H for immediate help. ...

                                               l.27       {\dummydata};
                     (That was another \errmessage.)

Package pgfplots Warning: the current plot has no coordinates (or all have been filtered away) on input line 27.

[warning /pgfplots/warning/plot without coordinates]

Package pgfplots Warning: You have an axis with empty range (in direction z). R eplacing it with a default range and clearing all plots. on input line 29.

[warning /pgfplots/warning/empty range cleared axis] LaTeX Font Info: External font cmex10' loaded for size (Font) <7> on input line 29. LaTeX Font Info: External fontcmex10' loaded for size (Font) <5> on input line 29.

However, instead of using a .csv format, if I stick with a table format (that is removing a comma between the data and also col sep = comma in the plot, then I get what I desired. However, the data I have is in .csv format (pretty big). So, instead of creating a huge data-set for y-axis, how can I achieve it with the above-mentioned script.

The one that works without a .csv format (and without creating a huge data-set for a different axis per-se):

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}

\pgfplotstableread{
T3 v11
0 0.66582
0.000125 0.66582
0.00025 0.66582
0.000375 0.66582
0.0005 0.66582
0.000625 0.66582
0.00075 0.66582
0.000875 0.66582
0.001 0.66582
0.001125 0.66582
}\dummydata
\begin{axis}[
    domain=-4:4,
    samples y=0, ytick={1,...,4},
]
{
    \addplot3 table [x =T3, y expr=1, z=v11]
      {\dummydata};
}
\end{axis}
\end{tikzpicture}
\end{document}

which would give me the desired output:

enter image description here

PS: This is just an example, in reality I use the external file to import my data for plotting purposes.

1 Answer 1

5

After moving col sep=comma to the right place, the errors are gone.

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\usepackage{pgfplotstable}
\begin{document}
\begin{tikzpicture}

\pgfplotstableread[col sep = comma]{
T3,v11
0,0.66582
0.000125,0.66582
0.00025,0.66582
0.000375,0.66582
0.0005,0.66582
0.000625,0.66582
0.00075,0.66582
0.000875,0.66582
0.001,0.66582
0.001125,0.66582
}\dummydata
\begin{axis}[
    domain=-4:4,
    samples y=0, ytick={1,...,4},
]
{
    \addplot3 table [x =T3, y expr=1, z=v11]
      {\dummydata};
}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

MINI-EXPLANATION: When you load the data, you need to tell pgfplots what the structure of the file is, i.e. how it is supposed to decompose it into rows and columns, i.e. cells. If you do not tell pgfplots that the columns are separated by commas, say, it will assume they are separated by spaces or tabs, which is why your second example worked. In your first example, pgfplots "thought" the first non-header row has only the cell 0,0.66582 rather than two cells 0 and 0.66582, and so on, which explains the error messages. And yes, I can see how this might be confusing, after all you specify only in the plot which column goes where.

3
  • Nice answer, could you briefly explain why we must do that change? Commented Nov 25, 2018 at 17:02
  • 1
    @Raaja I added some mini-explanation.
    – user121799
    Commented Nov 25, 2018 at 17:09
  • 1
    Thanks for the little brief, its clear for me now! Commented Nov 25, 2018 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .