Graphing time-series

5

I'm currently trying to use data gathered as a function of time (here, the fluorescence of a biological sample), but am new to Mathematica and don't know how to properly specify axis relations (and units, etc.).

Using ExcelLink 3.5, I've imported the data for one of many drugs whose effect on the fluorescence function I want to analyze. Because of how the information was imported, the listed data I've collected for $f(t)$ is in a list, with no reference to what the independent variable (x-axis) values should be. I made my plot with

ListPlot[{28,32,37,66}]

producing x-axis values of {1, 2, 3, 4} by default, and not t in minutes, which would be {300, 600, 1200, 1440} in my case).

How can I make a plot with the proper x-axis values?

Ghersic

Posted 2013-04-13T20:17:42.270

Reputation: 1 077

Does your problem of setting the DataRange for ListPlot have anything to do with ExcelLink? If no, please modify your question and title accordingly.

– István Zachar – 2013-04-14T10:57:06.043

Answers

10

If the points were regularly spaced you could use Datarange:

ListPlot[{28, 32, 37, 66}, DataRange -> {300, 1440}]

enter image description here

However, they aren't spaced regularly, so in one way or another you have to specify the x values. Like this, for instance:

ListPlot[Transpose[{{300, 600, 1200, 1440}, {28, 32, 37, 66}}]]

enter image description here

BTW ExcelLink is not really necessary to get data from Excel. Mathematica's Import function can import data in various Excel compatible formats (XLS, XLSX, CSV, TSV).

Sjoerd C. de Vries

Posted 2013-04-13T20:17:42.270

Reputation: 63 549

That looks useful, however, I need to graph it so that those four data points within ListPlot occur specifically at times {300,600,1200,1440}.

I will certainly look through the documentation on DataRange, though! Thank you.

I read about that prior to learning of ExcelLink. Do you know of an efficient way to import Excel data that will incorporate the data for both f(t) and t itself?

I'm not particular to ExcelLink, I just assumed it was the easiest route. – Ghersic – 2013-04-13T20:32:14.790

@Ghersic See update – Sjoerd C. de Vries – 2013-04-13T20:37:09.050

@Ghersic Your question seemed to imply that you only had access to the y-values. If the t values are on the same sheet you can do a simple Import (type XLS or XLSX in the doc center search bar) and get the columns that contain the data from the result using the usual list manipulating functions.

– Sjoerd C. de Vries – 2013-04-13T20:41:37.647

Thanks. I do have access to both the y- and t-data. I will try doing this using Import command, extracting the lists from the rows, and inputting the ListPlot command in the format you laid out in your original answer.

This does sound simpler than using ExcelLink. – Ghersic – 2013-04-13T20:46:39.813

@Ghersic It turns the separate y and t lists into a list of y,t pairs. – Sjoerd C. de Vries – 2013-04-13T21:57:30.487

Ah, that solves the last of my problems then (my linear algebra has always been shoddy). Thank you again. – Ghersic – 2013-04-14T05:41:18.197

If you don't like the linear algebraic Transpose, you can do the same thing with Thread, for instance: Thread[{{300, 600, 1200, 1440}, {28, 32, 37, 66}}] – bill s – 2013-04-24T06:44:44.530

4

Using Mathematica's Time-Series framework

If you have imported or entered data as tuples (e.g. $\Big\{(time_1,value_1), (time_2,value_2), \ldots \Big\}$ or as a list of values $\textbf{vals}$ with the corresponding list of times $\textbf{times}$ then the most natural thing to do since Version 10 is to use the Time Series - framework which has made representing TemporalData quite nice and easy.

So in your case you would have:

vals = { 28, 32, 37, 66 };
times = {300, 600, 1200, 1440};

data = EventSeries[ vals, { times } ];

ListPlost @ data (* or more cumbersome data[ "Path" ] // ListPlot *)

Graph for the time series

This is equivalent to having tuples:

tuples = Transpose @ { times, vals };
EventSeries @ tuples // ListPlot

gwr

Posted 2013-04-13T20:17:42.270

Reputation: 11 083