Message Boards Message Boards

0
|
14601 Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

[?] Change x axis units from seconds to minutes?

Posted 7 years ago

Is there any way to overwrite the x-axis values in a plot?

I have numerical solution to a differential equation, the solution is plotted against time in seconds. However, I want to change the x-scale of my plot to show minutes, without having to go back and solve the differential equation again.

Plot[Evaluate[(((y[x]) /. solutionNum))], {x, 0, signalLength}, 
       PlotRange -> {{0, signalLength}, {All, All}}, 
       FrameLabel -> {"time / s", "temperature / ºC" }, PlotLegends -> {"Model"}];

I want to overwrite the x-axis values to show for instance 0-250 minutes, and not 0-15000 seconds, without having to redo my soluton .

Thanks in advance! enter image description here

POSTED BY: Sara K
6 Replies

Sara,

I like to use TimeSeries because you can shift and scale things later (if you need to compare real data, etc.).

Using the example from NDSolve:

s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}][[1]]

The answer is in seconds so I construct a TimeSeries from it that has minute spacing:

ListLinePlot[TimeSeries[(y /. s)[Range[0, 30, .1]], {0, 30/60}], 
 PlotRange -> All]

to get:

enter image description here

POSTED BY: Neil Singer
Posted 7 years ago

That will be really helpful for me also in other projects. Thanks a lot!

POSTED BY: Sara K

If you are using the Quantity system, you should be able to use an option called TargetUnits.

http://reference.wolfram.com/language/ref/TargetUnits.html

Posted 7 years ago

Thanks!

POSTED BY: Sara K

Rescaling of your variable x:

Plot[Evaluate[(((y[60x]) /. solutionNum))], {x, 0, signalLength/60}, PlotRange -> {{0, signalLength}, {All, All}}, FrameLabel -> {"time / min", "temperature / ÂșC" }, PlotLegends -> {"Model"}];

would do the trick, without the data it is tricky to test..

POSTED BY: Sander Huisman
Posted 7 years ago

Thanks a lot!

POSTED BY: Sara K
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract