TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi i have two plot with two linear regression but the legend show the same equation for the straight line... I haven't made a MWE because I thought it isn't needed---Is it?

97 1.0
96 15
96 29.2
96 32
98 42.4
98 59.2
98 66.1
97 84.4
100 94.0

\pgfplotstablecreatecol[linear regression]

\xdef\slopeA{\pgfplotstableregressiona} %<-- might be handy occasionally

0.05 0.17
0.05 0.041
0.05 0.023
0.1 0.332
0.1 0.089
0.1 0.041
0.15 0.5
0.15 0.132
0.15 0.06

\pgfplotstablecreatecol[linear regression]

\xdef\slopeB{\pgfplotstableregressiona} %<-- might be handy occasionally

and in every plot i put this for make a the legend...

$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}

This one of my plot...

\addplot [%
    point meta=explicit,
    scatter/use mapped color={draw=mapped color,fill=mapped color},
    draw=none, forget plot]table[meta=X] {\tableA};

\addplot [mesh,mesh line legend,point meta=x,domain=95.2:99.8,very thick,samples=1000] {\slopeA*x+\interceptA};
share|improve this question
You should use \slopeA and \slopeB in your legend: That's why you used the \xdef assignment, so you'd be able to refer to the parameters later on. – Jake Jun 21 '12 at 21:01
Is a MWE needed? Yes, definitely. – egreg Jun 21 '12 at 21:18
up vote 4 down vote accepted


$\pgfmathprintnumber{\slopeB} \cdot x
\pgfmathprintnumber[print sign]{\interceptB}$}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.