# Scientific notation in plot title

I have problem with displaying variables in scientific notation in plot title. Below is my code sample,

ClearAll;
f1[a_,b_,c_]:=a*x^2+b*x^3+c;
f2[a_,b_,c_]:=a*x+b*x^2+(2-x)*c;
x=Range[0,10,0.01];
a1=1.0;b1=2.0;c1=0.000000001;
f3=f2[a1,b1,c1]+f1[a1,1,c1];
plot1=ListPlot[f3,PlotLabel->Style[" a="<>ToString[a1]<>"   b="<>ToString[b1]<>" c="<>ToString[c1]]]


It works on simple decimal numbers. However, longer decimals do not display properly. How to fix that?

• With that many data points ListLinePlot produces a clearer, sharper plot. However, ListPlot has an advantage if you you want to include Tooltip. – Bob Hanlon Dec 6 '17 at 16:17

I don't see any reason to use ToString, and I especially avoid using ToString[expr, TraditionalForm] if at all possible. Instead, I would do:

ListPlot[
f3,
PlotLabel->Row[{a==a1, b==b1, c==c1},"    "]
]


• Until now I also used often ToString to produce labels in plots, What is the disadvantage of it? – mrz Dec 7 '17 at 20:09
• @mrz Anything you can do with ToString you should be able to do with Row. ToString has issues. For instance ToString[1.1*^-8] or ToString[Subscript[x,1]]. And I don't like StandardForm/TraditionalForm because I don't like linear syntax (e.g., "\!(*SubscriptBox[(x), (1)])"). Finally, InputForm typically isn't useful (e.g., ToString[Subscript[x, 1], InputForm]). I much prefer creating an expression instead of a string as a label. – Carl Woll Dec 7 '17 at 20:34
PlotLabel ->
Style[" a=" <> ToString[a1, TraditionalForm] <> "   b=" <>
ToString[b1, TraditionalForm] <> " c=" <>


I am not sure if you want to write all decimals or not. I am assuming the first case as the statement says "It works on simple decimal numbers". Thus, be advised you can increase the threshold for representing number in the scientific form by using ScientifcNotationThreshold in NumberForm along the numerator of digits and decimals, and along the suggestion of @BobHanlon for a clearer plot:

ClearAll;
f1[a_, b_, c_] := a*x^2 + b*x^3 + c;
f2[a_, b_, c_] := a*x + b*x^2 + (2 - x)*c;
x = Range[0, 10, 0.01];
a1 = 1.0000000000034; b1 = 2.0; c1 = 0.000000001;
f3 = f2[a1, b1, c1] + f1[a1, 1, c1];
plot1 = ListLinePlot[f3,
PlotLabel ->
Row[Style[#, 12, Black, Bold, SingleLetterItalics -> False] & /@
{a ==NumberForm[a1, {18, 17}, ScientificNotationThreshold -> {-25, 25}],
b == b1,
c == NumberForm[c1, {10, 9}, ScientificNotationThreshold -> {-15, 15}]
}, Invisible["spc"]
]
]


## Edit

The suggestions by Carl have been added (avoid use of ToString whenever posible). It is also included a second plot when the label is dangerously long by using Column with option Aligment-> Left, instead of Row.

• If you change b to 2*^-17 the output is horrendous. This is one of the reasons I strongly discourage the use of single-argument ToString. – Carl Woll Dec 7 '17 at 18:16
• I am not sure what you mean. However, guessing it, just use NumberForm as for a1 and c1... – José Antonio Díaz Navas Dec 7 '17 at 18:18
• I'm sorry, I meant change a1 = 1.0000000000034 to a1=2.0*^-17. – Carl Woll Dec 7 '17 at 18:24
• @CarlWoll change to ToString@NumberForm[a1, {18, 17}, ScientificNotationThreshold -> {-25, 25}] ;)) – José Antonio Díaz Navas Dec 7 '17 at 18:27
• Oh @CarlWoll, if row makes a very long label, then change Row to Column – José Antonio Díaz Navas Dec 7 '17 at 18:29