3

I've got a few macros that perform floating point lookups and calculations for me and I'm interesting in plotting their results. They're the kind of calculation which requires if/else, so they can't be easily written as a simple math formula for \addplot. I've been able to plot the results using a \foreach, but only by having a separate \addplot for each point in the series:

\foreach \x in {1,...,100}{
  \edef\temp{\noexpand \addplot coordinates{ (\x,\myMacro{\x}) }; }
  \temp
}

Granted, I'm sure that I could force it to look like one data series, but that seems like a very inelegant solution. Is it possible to define a data series where y values are provided by a LaTeX macro? Something like

\addplot{
   \coordinates{
     foreach \x in {1,...,100){
       (\x,\myMacro{\x})
     }
   }
};

or

\addplot[variableICanPassToMacro=\x, domain=1:100] ({\x},{\myMacro{\x}});

?

user1476176
  • 1,225
  • 2
    You should be able use \pgfmathdeclarefunction. An example of which is at How to define a parameterized command to be consumable in \pgfmathdeclarefunction?. If you provide an actual macro that computes the results that you desire it would be easier to give you a more detailed answer. Ideally, it would be best if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. – Peter Grill Apr 07 '14 at 02:40
  • 2
    Welcome to the TeX.SX! Could you please make it a full working example starting with \documentclass... and ending with ...\end{document}? It helps solvers a lot to start working on it. – Malipivo Apr 07 '14 at 03:37
  • \pgfmathdeclarefunction is the answer I was looking for, thanks. – user1476176 Apr 13 '14 at 18:45
  • I created a MWE, but my question has changed a fair bit now that I know about \pgfmathdeclarefunction, so I think it's more appropriate to post it as a new one. The new question is here: http://tex.stackexchange.com/questions/171263/plotting-a-function-defined-with-pgfmathdeclarefunction – user1476176 Apr 13 '14 at 19:34

0 Answers0