# Having problems with ListPlot and a PaddedForm wrapper

I defined a function f[x_] = x^3 2 x. Then I had to construct a table showing vertically, the values of f corresponding to x on the interval [-3,3] in increment of 0.5.

So, I did this:

f[x_] = x^3 - 2 x;
p = Table[{a, b}, {x, -3, 3, .5}];
TableForm[p,
TableAlignments -> Center]

I had my answers and so far it was ok. But next, I had to plot the set of values with heavy dots. So I did this:

ListPlot[p];

But now there's an error saying:

Co-ordinate -3.0 in {-3.0,-21.000} is not a floating-point number ....

How do I fix this?

• Remove the PaddedForm wrapper: ListPlot[Table[{x, f@x}, {x, -3, 3, .5}]]. – Öskå May 5 '14 at 18:07
• @Öskå You reply or Community Wiki or something? :) – Dr. belisarius May 5 '14 at 18:12
• ahahah, I'm on it! Wiki! – Öskå May 5 '14 at 18:13

In the PaddedForm documentation you can find:

PaddedForm acts as a "wrapper", which affects printing, but not evaluation.

This means that PaddedForm is just an inert wrapper which does not evaluate to something numeric. ListPlot requires numbers but after wrapping a number with PaddedForm or any other inert wrapper it does not a number anymore. One could check it with NumberQ:

ClearAll["`*"]
NumberQ /@ {PaddedForm[1, {2, 1}], g[2], Hold[3], 1[4]}
{False, False, False, False}

Of course ListPlot will not display anything when a list containing no numbers is passed to it.

The following will work:

f[x_] := x^3 - 2 x;
ListPlot[Table[{x, f@x}, {x, -3, 3, .5}]]

• That might explain why I can't even upvote my own CW answer :( – Öskå May 5 '14 at 18:20
• @Öskå Your interpretation of the Documentation statement is not correct: Plotting in Mathematica generally does not imply displaying or printing anything at all! The reason for the error message is clear: a number wrapped by arbitrary Head is not a number anymore. Instead of PaddedForm there could be any other inert wrapper, for example g or Hold or even a number like this: 1[1]. Try ListPlot[{g[1], Hold[2], 1[1]}] - nothing is displayed because there are no numbers in the list! One could check it with NumberQ: NumberQ /@ {g[1], Hold[2], 1[1]} gives {False, False, False}. – Alexey Popkov May 5 '14 at 22:40
• @AlexeyPopkov that's the reason why it's a Community Wiki :) But thanks for the info :) I based my assumptions on that answer. – Öskå May 5 '14 at 22:56
• @Öskå That answer is correct and does not contradict me in any sense. One thing that will help you to understand that answer deeper is that now FrontEnd is able to render Graphics directly but before Mathematica 6 FrontEnd was able to render only PostScript and Bitmap graphics and the Kernel converted Graphics to PostScript for the purposes of displaying in the FrontEnd. That complicated things a bit. Also Graphics and "graphics" has different meanings when speaking about Mathematica. – Alexey Popkov May 5 '14 at 23:06
• I see. Thanks for the info and for correcting the answer :) – Öskå May 5 '14 at 23:18