1

I want to plot the following data, i am using the CSV file, and pgfplotstable package.

  1. (0,2.42130785530195E-02),
  2. (113.8,2.42130785530195E-02),
  3. (227.6,2.42130781357695E-02),
  4. (341.3,2.42130779271445E-02),
  5. (455.1,2.42130777185196E-02),
  6. (568.9,2.42130775098946E-02),
  7. (682.7,2.42130773012696E-02),
  8. (796.4,2.42130770926447E-02),
  9. (910.2,2.42130768840197E-02),
    1. (1024,2.42130766753947E-02),

enter image description here

I am getting this plot

The Minimal Working Environment :

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{siunitx}

\begin{document}
\pgfplotstableread[col sep = comma]{lossprob_jin1.csv}\loadedtable

\begin{figure*}
\centering
\begin{tikzpicture}
\begin{axis} [xlabel=Buffer-Size (bits),ylabel=Loss Probability (\%), legend entries = {H=0.6448}]
\addplot table [x=xsw, y=plp, col sep=comma] {\loadedtable} ;
\end{axis}
\end{tikzpicture}
\end{figure*}
\end{document}
  • Please add a full minimal working example of your code. In particular, you seem to be plotting your values 'backward' (x and y swapped) which is not immediately obvious. Given the very narrow x range, what do you expect to see? – Joseph Wright Apr 25 '15 at 6:10
  • ymin = 2.421307,68840197 ymax = 2.421307,85530195 there is change in last 8 floating points the first 6 floating points are same for all the data – Moody Apr 25 '15 at 6:54
1

Those differences are too small for PGFPlots to handle. You can work around this by subtracting a fixed amount from all numbers using gnuplot and "faking" the labels:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    scaled y ticks=false,
    y tick label style={
        /pgf/number format/fixed,
        /pgf/number format/precision=0
    },
    yticklabel=0.02421307\pgfmathprintnumber{\tick},
    x tick label style={
        /pgf/number format/1000 sep={}
    },
    xlabel=Buffer size in bits,
    ylabel=Loss proabiblity in \%
]
\addplot[raw gnuplot, mark=*] gnuplot {
    plot 'data.dat' using 2:($1-0.02421307)*1e10;
};
\end{axis}
\end{tikzpicture}
\end{document}

But honestly you should probably find some other way to display the effect of the buffer size on the loss probability (are you sure that this effect is even real, or significant?)

1

This is a work-around using LuaTeX

\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.12} 
\usepackage{siunitx}
\begin{document}
\pgfplotstableread
{
x y 
0     2.42130785530195E-02
113.8 2.42130783443945E-02
227.6 2.42130781357695E-02
341.3 2.42130779271445E-02
455.1 2.42130777185196E-02
568.9 2.42130775098946E-02
682.7 2.42130773012696E-02
796.4 2.42130770926447E-02
910.2 2.42130768840197E-02
1024  2.42130766753947E-02
}\Bsizeloss
\begin{tikzpicture}
  \begin{axis}[xlabel={Buffer-Size (bits)},
              ylabel={Loss Probability, \% ($\times 10^{10}-242130700$)},
              ytick={67,73,79,85}, 
              legend entries = {H=0.6448},
              grid = major
              ]
  \addplot+ table[y expr=\directlua{tex.print(\thisrow{y}*1E10-242130700)},x=x] {\Bsizeloss}; 
  \end{axis}
\end{tikzpicture}

enter image description here

0

You can achieve the same as in AboAmmar's answer also in PDFLaTeX, using package xintexpr which can handle numbers with arbitrary number of digits.

\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.12} 
%\usepackage{siunitx}% seems not needed in this mwe
\usepackage{xintexpr}
\begin{document}
\pgfplotstableread
{
x y 
0     2.42130785530195E-02
113.8 2.42130783443945E-02
227.6 2.42130781357695E-02
341.3 2.42130779271445E-02
455.1 2.42130777185196E-02
568.9 2.42130775098946E-02
682.7 2.42130773012696E-02
796.4 2.42130770926447E-02
910.2 2.42130768840197E-02
1024  2.42130766753947E-02
}\Bsizeloss
\begin{tikzpicture}
  \begin{axis}[xlabel={Buffer-Size (bits)},
              ylabel={Loss Probability, \% ($\times 10^{10}-242130700$)},
              ytick={67,73,79,85}, 
              legend entries = {H=0.6448},
              grid = major
              ]
  \addplot+ table[y expr=\xintthefloatexpr\thisrow{y}*1E10-242130700\relax,x=x] {\Bsizeloss}; 
  \end{axis}
\end{tikzpicture}
\end{document}

PDFLaTeX produces:

enter image description here

Perhaps in more general cases one would need braces for the expression after y expr (especially if the expression used a function with commas to separate arguments).

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.