1

I am trying to plot the data by altering the signs of orginal data for both X-Axis and Y-Axis columns data, How do i proceed to get this, i have large data so could write, so i minimize my problem. Thanks for any suggestion. My data after altering the signs for each column data will be like this

 Ax By
 -1 -0.5
 -2 1
 -3 -1.5

I want to do without doing manually, Below is my MWE

 \begin{filecontents}{data.txt}
 Ax By
 1 0.5
 2 -1
 3 1.5
 \end{filecontents}

 \documentclass[10pt]{article}

 \usepackage{pgfplotstable}
 \usepackage{pgfplots}

 \newcommand{\mydataOAA}{data.txt}


 \begin{document}
 \hspace*{-3cm} \begin{tikzpicture}[scale=1.9]
 \begin{axis}[
 %scaled y ticks=base 10:6,
 %x dir=reverse,
 %y dir=reverse,
   xticklabel style={black} ,
   yticklabel style={black} ,
   xlabel=\color{black}-$\textrm{V}_{\hspace*{-0.5mm}\tiny\textrm{d}}$($V$),
   ylabel=\color{black}-$\textrm{I}_{\tiny\textrm{d}}$($A$),ylabel near ticks,legend pos=north west,legend style={font=\fontsize{4}{5}\selectfont}]
 \addplot[mark=line,brown] table [y=By, x=Ax, col sep=space]{\mydataOAA};
 \addlegendentry{\color{black}$V_{g}$=0V}
 \end{axis}

 \end{tikzpicture}
 \end{document}

2 Answers 2

1

Is that what is needed ?

\begin{filecontents}{data.txt}
 Ax By
 1 0.5
 2 -1
 3 1.5
 \end{filecontents}

 \documentclass[10pt]{article}

 \usepackage{pgfplotstable}
 \usepackage{pgfplots}

 \newcommand{\mydataOAA}{data.txt}


 \begin{document}
 \hspace*{-3cm} \begin{tikzpicture}[scale=1.9]
 \begin{axis}[
 %scaled y ticks=base 10:6,
 %x dir=reverse,
 %y dir=reverse,
   xticklabel style={black} ,
   yticklabel style={black} ,
   xlabel=\color{black}-$\textrm{V}_{\hspace*{-0.5mm}\tiny\textrm{d}}$($V$),
   ylabel=\color{black}-$\textrm{I}_{\tiny\textrm{d}}$($A$),ylabel near ticks,legend pos=north west,legend style={font=\fontsize{4}{5}\selectfont}]

 \addplot[mark=line,brown] table [y expr=-\thisrow{By}, % <----------
                                  x expr =-\thisrow{Ax}, % <---------
                                  col sep=space]{\mydataOAA};

 \addlegendentry{\color{black}$V_{g}$=0V}
 \end{axis}

 \end{tikzpicture}
 \end{document}
0

You can make use of the x expr feature (and friends) to accomplish that. Please have a look at the code how to explicitly use it. (Please note that I removed everything unrelated from your code.)

% used PGFPlots v1.17
\begin{filecontents}{data.txt}
    Ax By
    1 0.5
    2 -1
    3 1.5
\end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}
        \addplot table [
            % for named columns you can use
            x expr={-1*\thisrow{Ax}},
            % for unnamed columns (i.e. there is no header row) you can use
            % (Please note that the numbering starts from 0.)
            y expr={-1*\thisrowno{1}},
        ] {data.txt};
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

You must log in to answer this question.

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