2
$\begingroup$

This question already has an answer here:

I've got an array of data shown in scientific form. Which looks like this:

x = {0.0001,ScientificForm[0.999890436521418]}

Now I'm trying to use ListPlot to plot this data, but the problem is that the point which is in Scientific form doesn't show up in my plot (only 0.0001 is shown).

ListPlot[x]

How can I cancel this ScientificForm curse off my data? There are Megabytes of data in this form, So I'd need a function to take care of them all for me. Thanks in advance :)

P.S I've tried using x = N[x,16], and some other number forms but no luck.

Edit: Kuba really helped with his comment. Thanks!

$\endgroup$

marked as duplicate by MarcoB, Community Mar 6 '17 at 16:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    $\begingroup$ ListPlot[x /. ScientificForm -> (# &)], in general don't keep **Form in data but use them only when you need to display something. $\endgroup$ – Kuba Mar 6 '17 at 11:20
  • 1
    $\begingroup$ at least closely related: 92885 $\endgroup$ – Kuba Mar 6 '17 at 11:55
  • 1
    $\begingroup$ And 92226 too. $\endgroup$ – m_goldberg Mar 6 '17 at 13:12
  • $\begingroup$ @Kuba Thanks! 48266 is exactly what I've been looking for! $\endgroup$ – Pedram Ashofteh Ardakani Mar 6 '17 at 14:13
3
$\begingroup$

Substituting any head that will act as the identity function for ScientificForm will work. I suggest Identity or Sequence; kuba suggests (#&). Any of these will work. Let's see how it goes with some data that better approximates having many data points to plot.

SeedRandom[0];
data =
  With[{n = 10},
    MapThread[{#1, ScientificForm[#2]} &, {.01 Range[n], RandomReal[1, n]}]];

Then using Identity, we get

ListPlot[data /. ScientificForm -> Identity]

plot

Update

Kuba raises the issue that, in the extended case where the ScientificForm expression contains options, Identity and Sequence will fail while (#&) does not. That is true and it makes (#&) much more robust; I highly recommend its use.

Here is another solution that is also robust.

SeedRandom[0];
data2 =
  With[{n = 10},
    MapThread[
      {#1, ScientificForm[#2, 10, DigitBlock -> 3]} &, 
      {.01 Range[n], RandomReal[1, n]}]];
ListPlot[data2 /. ScientificForm[u_, ___] -> u]

plot

$\endgroup$
  • 1
    $\begingroup$ Identity will complain about ScientificForm[0.999890436521418, DigitBlock -> 3] and Sequence may introduce unexpected output. I know it is not the OP case be can quickly escalate. $\endgroup$ – Kuba Mar 6 '17 at 14:01
  • $\begingroup$ @Kuba. You make a good point. But as you say, that case was not considered in the user's question. $\endgroup$ – m_goldberg Mar 6 '17 at 14:25
  • $\begingroup$ @Kuba. BTW this is a good example of why you should write a real answer and not spread a superior answer over multiple comments. If you had written a real answer, where you discussed how (#&) has the advantage of working in extended cases, this question would have a better answer than mine. $\endgroup$ – m_goldberg Mar 6 '17 at 14:33
  • $\begingroup$ Sorry, didn't want to mess things up, I just don't always have time to write a good answer, nor I find it easy to phrase it nicely. I also suspected this is a duplicate but I didn't found it quickly. Next time I will add a comment that this is the case and that I used #& intentionally :-/ $\endgroup$ – Kuba Mar 6 '17 at 14:43
  • $\begingroup$ ToExpression could help sometimes too, especially when data is saved in rational form. $\endgroup$ – Pedram Ashofteh Ardakani Mar 13 '17 at 23:34

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