3
$\begingroup$

I want to make a plot of data with big values by x. My code is this

myList = {{10^15, 1}, {10^15 + 1, 1.2}, {10^15 + 2, 1.5}, {10^15 + 3, 1.1}}
ListPlot[myList, PlotRange -> {{10^15, 10^15 + 3}, {0, 2}}]

but when I get a plot, it looks like x always the same enter image description here

and look like mathematica ignores my PlotRange and make it from 0 to 2*10^15.

How can I force mathematica to make x axis from 10^15 to 10^15 + 3?

UPDATE1

I also have similar problem if I want to plot function like this

Plot[Sin[x],{x,10^15, 10^15 + 3}] 

enter image description here

of course if I convert it to the Table and use solution from Simon Rochester's answer, it will work.

ListPlot[Transpose[Transpose[Table[{x,Sin[x]}, {x,10^15, 10^15 + 3, 0.1}]] - {10^15, 0}], PlotRange -> {{0, 3}, {-1, 1}}]

enter image description here

but is there any way to do it directly with Plot[]?

I put this example to mathematica cloud. I hope it will work for everyone.

UPDATE2

I can do it with Plot of function like this

Plot[Sin[10^15+x],{x,0, 3}]

But somehow graph looks strange :) enter image description here

$\endgroup$
5
  • 1
    $\begingroup$ Interestingly, for me the boundary for this breaking appears to be at 4.398046511103750*^13 , which doesn't have much numerical relevance as far as I know. $\endgroup$
    – lowriniak
    Commented Dec 8, 2016 at 11:06
  • $\begingroup$ Yes, it is strange. Might be it is a mathematica bug. $\endgroup$
    – Zlelik
    Commented Dec 8, 2016 at 12:13
  • 1
    $\begingroup$ At first glance this looks like a bug in Graphics, but perhaps it is merely a design limitation or I misunderstand. e.g. Graphics[Point[myList], PlotRange -> {{10^15, 10^15 + 3}, {0, 2}}, AspectRatio -> 1/GoldenRatio, Axes -> True] also does not work "correctly." $\endgroup$
    – Mr.Wizard
    Commented Dec 8, 2016 at 15:41
  • 2
    $\begingroup$ that last jagged plot is a precision problem, try Plot[Sin[10^15 + x], {x, 0, 3}, WorkingPrecision -> 20] $\endgroup$
    – george2079
    Commented Dec 8, 2016 at 21:29
  • $\begingroup$ @george2079 Yes, thanks. Your example works fine. $\endgroup$
    – Zlelik
    Commented Dec 9, 2016 at 10:42

2 Answers 2

4
$\begingroup$

Might I suggest not making a plot like that? Whatever information that you are trying to get across will likely be clearer if you plot with x-values relative to $10^{15}$ and note that in the axes label or the caption:

ListPlot[Transpose[Transpose[myList] - {10^15, 0}], PlotRange -> {{0, 3}, {0, 2}}]

Mathematica graphics

If you really want big numbers on the axis, you could put them there by hand:

ListPlot[Transpose[Transpose[myList] - {10^15, 0}], PlotRange -> {{0, 3}, {0, 2}}, 
  Ticks -> {Join[Table[{i, i + 10^15}, {i, 0, 3, 3}], Table[{i, "", {.01, 0}}, {i, 0, 3, .5}]], Automatic}
]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Wow. It is very good answer. But what can I do if I need to plot some function like this: Plot[Sin[x],{x,10^15, 10^15 + 3}] ? $\endgroup$
    – Zlelik
    Commented Dec 8, 2016 at 10:11
0
$\begingroup$

Just to summarize for the people who will search it. There are 3 solutions:

  1. Like suggested by Simon Rochester

    myList = {{10^15, 1}, {10^15 + 1, 1.2}, {10^15 + 2, 1.5}, {10^15 + 3, 1.1}} ListPlot[Transpose[Transpose[myList] - {10^15, 0}], PlotRange -> {{0, 3}, {0, 2}}]

enter image description here

  1. Solution for problem Plot[Sin[x],{x,10^15, 10^15+3}] based on Simon Rochester's answer

    ListPlot[Transpose[Transpose[Table[{x,Sin[x]}, {x,10^15, 10^15 + 3, 0.1}]] - {10^15, 0}], PlotRange -> {{0, 3}, {-1, 1}}]

enter image description here

  1. Solution with plot

    Plot[Sin[10^15+x], {x,0,3}]

enter image description here

and to avoid steps

Plot[Sin[10^15+x],{x,0,3}, WorkingPrecision->20]

enter image description here

and with proper ticks (from Simon Rochester's example)

Plot[Sin[10^15+x],{x,0, 3}, Ticks -> {Join[Table[{i, i + 10^15,{0.02,0}}, {i, 0, 3, 1}], Table[{i, "", {0.01, 0}}, {i, 0, 3, .1}]], Automatic},WorkingPrecision->20]

enter image description here

All problem and solution are available here. It is mathematica cloud, I am not sure how long it will be available.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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