Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Hi i have two plot with two linear regression but the legend show the same equation for the straight line... i have not made a MWE because I thought that does not serve. Is needed?

\pgfplotstableread{
X Y
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
}\tableA

\pgfplotstablecreatecol[linear regression]
{regression}
{\tableA}

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



\pgfplotstableread{
X Y
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
}\tableB

\pgfplotstablecreatecol[linear regression]
{regression}
{\tableB}

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

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

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

This one of my plot...

\addplot [%
    point meta=explicit,
    scatter,
    scatter/use mapped color={draw=mapped color,fill=mapped color},
    mark=*,
    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
1  
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
2  
Is a MWE needed? Yes, definitely. –  egreg Jun 21 '12 at 21:18
add comment

1 Answer

THANKS JAKE

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

Your Answer

 
discard

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.