2

I have found a small issue with negative values graph in tikzpicture. My source code is very simple:

\documentclass[12pt, a4paper]{report}

\usepackage[czech]{babel}
\usepackage[utf8]{inputenc}
\usepackage{tikz} 
\usepackage{pgfplots}

\begin{document}
\begin{figure}[ht!]
\center
\begin{tikzpicture}[]
    \begin{axis}[xlabel={Power (dBm)}, ylabel={log BER (---)},
                                width=10cm,
                                height=8cm,
                                xmin=-10,   xmax=-25,
                                ymin=-1,  ymax=-25, 
                                legend pos=north east, grid=major]%or north west, ... ,outer north east
                \addplot file[skip first] {graphs/1-32.txt};
                \addplot file[skip first] {graphs/1-64.txt};
        \addlegendentry{1:32}        
                \addlegendentry{1:64}
   \end{axis}
\end{tikzpicture}
\caption{Power vs. log BER}
\label{}
\end{figure}

\end{document}

I can include my 1:32.txt file:

x  y  
-18.28  -20.00392635
-19.42  -16.09799711
-20.57  -12.16749109
-21.72  -8.70333481
-22.87  -5.931814138
-24.06  -4.004803708
-25.23  -2.721246399

and 1:64 file:

x  y  
-18.13  -20.99567863
-19.29  -17.79263496
-20.43  -13.67778071
-21.24  -9.779891912
-22.73  -6.671620397
-23.88  -4.447331784
-25.36  -3
-25.78  -2.301029996

Both has negative values and my graph is not draw correctly.

The picture shows what I got. I added the black line with expected line and green colors represents the values of axis. I got this graph.

Thanks in advance for your time and ideas.

1

I think you are looking for the key 'x dir=reverse'. Without the reversed direction, -25 is left and -18 is right as in most plots.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3} %important, must be equal or higher than 1.3
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[xlabel={Power (dBm)}, ylabel={log BER (---)},
    legend pos=north east, grid=major,
    x dir= reverse,
    axis x line* = top, %draw x axis line on top
    extra description/.code={\draw (0,0) -- (1,0);} %draw an extra line where the original x-axis was
    ]
    \addplot table[x=power,y=BER] {
        power   BER     
        -18.28  -20.00392635
        -19.42  -16.09799711
        -20.57  -12.16749109
        -21.72  -8.70333481
        -22.87  -5.931814138
        -24.06  -4.004803708
        -25.23  -2.721246399
    };
    \addplot table[x=power,y=BER] {
        power   BER
        -18.13  -20.99567863
        -19.29  -17.79263496
        -20.43  -13.67778071
        -21.24  -9.779891912
        -22.73  -6.671620397
        -23.88  -4.447331784
        -25.36  -3
        -25.78  -2.301029996
    };
    \addlegendentry{1:32}        
    \addlegendentry{1:64}
    \end{axis}
    \end{tikzpicture}
\end{document}
  • Dear JLo815, yes, it is. Do you know how to move x-axis labels from bottom to the top? – Thomas Feb 19 '17 at 6:40
  • edited my answer – JLo0815 Feb 19 '17 at 9:30

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.