5

My question is related to Calculate and draw difference of two plots automatically, if in that site asking how to make a-b, I am asking you how to make plots as result of a/b and a*b and if you dont mind also from a+b.

9

This answer assumes that even though you refer to Calculate and draw difference of two plots automatically , you might have more freedom with respect to the format of your data.

The data format of the other question is ... well, complicated because there is no normalized, direct relation between the coordinate sets: the first N rows make up the first plot and the last N rows make up the second.

If you have one table and each plot is defined by means of selected columns rather than rows, you have a huge degree of freedom.

An example (using the data of the other request) could be

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.3} % label placement

\begin{document}

\begin{tikzpicture}
\begin{axis}

\addplot table[x=x,y expr=\thisrow{a}/\thisrow{b}] {
x a  b
1 1  1  
2 6  7  
3 10 13 
4 13 17 
5 15 20 
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}
\addplot table[x=x,y=a] {
x a  b
1 1  1  
2 6  7  
3 10 13 
4 13 17 
5 15 20 
};
\end{axis}
\end{tikzpicture}
\end{document}

The first axis consists of an \addplot table[...] statement with inline coordinates - and three columns: x is clear, a and b as well. The combination is done using the options: x=x defines the x coordinates and y expr=... defines a mathematical expression in which \thisrow{<colname>} expands to the value of one specific column. That allows to define any supported mathematical expression using as many columns as you like (from the "current" row).

The second axis is a simpler approach in which y=a selects a particular column without doing any extra computation.

In short: if you provide the data in a suitable format (e.g. a correctly normalized table in which the data is identified by columns), you can easily apply a very wide range of supported mathematical operations.

| improve this answer | |
  • thanks, and as your suggestion, I include my data sample after following your suggestion – limpato Jul 9 '12 at 4:55

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.