Group Abstract Group Abstract

Message Boards Message Boards

0
|
11.1K Views
|
21 Replies
|
17 Total Likes
View groups...
Share
Share this post:

[?] Plot a table with sequence of dates?

Hi,

I am trying to draw a table like below. How can I make this work properly?

list = {{"Washington", "Washington", "Washington", "Washington", 
   "Washington", "Washington", "Washington"}, {1990.`, 1991.`, 1992.`,
    1993.`, 1994.`, 1995.`, 1996.`}, {"2", "3", "4", "5", "6", "7", 
   "8"}, {"400.3", "60.7", "46.8", "21.7", "16.4", "61.0", 
   "12.2"}, {"", "", "", "", "", "", ""}, {"Texas", "Texas", "Texas", 
   "Texas", "Texas", "Texas", "Texas"}, {1994.`, 1995.`, 1996.`, 
   1997.`, 1998.`, 1999.`, 2000.`}, {"1", "2", "3", "4", "5", "6", 
   "7"}, {"29.4", "58.6", "50.7", "56.4", "30.0", "37.5", "35.2"}}

enter image description here

POSTED BY: M.A. Ghorbani
21 Replies

Hi Rohit,

I looked again. You are right absolutly. I really appreciate your help. Rohit, may I ask you about the last status Of complex network program? My friends and I look forward to see the incredible skill of you and the power of Mathematica in these kind of topics .

Thank you for your time.

POSTED BY: M.A. Ghorbani
Posted 6 years ago

Hi Mohammad,

The results look right to me. What were you expecting to see?

POSTED BY: Rohit Namjoshi

Hi Rohit,

Could you please have a look at the outputs for different intervals?

intervals = <|"Washington" -> Interval[{1966, 2012}], 
   "Texas" -> Interval[{1970, 2014}], 
   "Ohio" -> Interval[{1930, 2015}], "Utah" -> Interval[{1966, 2010}],
    "Kansas" -> Interval[{1960, 2018}]|>;

intervals // 
  Select[IntervalMemberQ[#, Interval[{1966, 2012}]] &] // Keys

{"Washington", "Ohio", "Kansas"}

intervals // 
  Select[IntervalMemberQ[#, Interval[{1971, 2012}]] &] // Keys

{"Washington", "Texas", "Ohio", "Kansas"}

intervals // 
  Select[IntervalMemberQ[#, Interval[{1930, 2015}]] &] // Keys

{"Ohio"}
POSTED BY: M.A. Ghorbani

Hi Rohit, thank you very much for this very interesting link! This is incredible! And it actually works:

enter image description here

Up to now I was always wondering how people can come up with undocumented functions ...

Best regards -- Henrik

POSTED BY: Henrik Schachner
Posted 6 years ago

Hi Henrik,

I think Interval only works with numeric values. Could use AbsoluteTime / FromAbsoluteTime to convert from / to DataObject. A Google search found this.

POSTED BY: Rohit Namjoshi

One more way: With

list1 = <|"Washington" -> {1966, 1967.`, 1968.`, 1969.`}, 
   "Texas" -> {1930, 1931.`, 1932.`, 1933.`, 1934.`, 1935.`}, 
   "Ohio" -> {1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970}|>;
minmax = MinMax /@ list1;
intv = Interval[{1963, 1969}];  (* the interval you are interested in *)
numlist = Interval /@ minmax;
intersect = Select[IntervalIntersection[#, intv] & /@ numlist, Length[#] != 0 &];

you can do:

Keys@intersect
(*  Out:  {"Washington","Ohio"}  *)
intersect["Ohio"]
(*  Out:  Interval[{1963,1969}]  *)

I found it surprising that I could not do any interval arithmetic with time intervals, e.g. this does not work:

IntervalIntersection[Interval[{DateObject[{1963}, "Year", "Gregorian", 1.`], DateObject[{1969}, "Year", "Gregorian", 1.`]}], 
 Interval[{DateObject[{1966}, "Year", "Gregorian", 1.`], DateObject[{1990}, "Year", "Gregorian", 1.`]}]]

Am I missing something?

POSTED BY: Henrik Schachner
Posted 6 years ago

Hi Mohammad,

Here is one way to do that

intervals = MinMax /* Round /* Interval /@ list1
intervals // Select[IntervalMemberQ[#, Interval[{1962, 1970}]] &] // Keys
(* {"Ohio"} *)

intervals // Select[IntervalMemberQ[Interval[{1962, 1970}], #] &] // Keys
(* {"Washington", "Ohio"} *)

To extract the values for a key

list1["Texas"]
(* {1930, 1931., 1932., 1933., 1934., 1935.} *)
POSTED BY: Rohit Namjoshi

Dear Henrik and Rohit,

What kind of features can be extracted from the timelines? For example :

Which city's (cities') data is between 1962 and 1970? Answer: Ohio

How many cities have data from 1962 - 1970? Answer: Ohio and Washington.

Is it possible to extract the time series values for a specific city? Thank you.

list1 = <|"Washington" -> {1966, 1967.`, 1968.`, 1969.`}, 
  "Texas" -> {1930, 1931.`, 1932.`, 1933.`, 1934.`, 1935.`}, 
  "Ohio" -> {1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970}|>

minmax = MinMax /@ list1

list2 = Interval /@ Map[DateObject@*ToString, minmax, {2}]

tlp = TimelinePlot[list2, ImageSize -> {1000, 200}]
POSTED BY: M.A. Ghorbani

Hello Mohammad,

For some reason your year date come as string - but they should be numbers. You can correct that like so:

list1 = Map[ToExpression, list1, {2}]
POSTED BY: Henrik Schachner

Why not simply

DeleteCases[#, ""] & /@ m

?

POSTED BY: Hans Dolhaine
POSTED BY: M.A. Ghorbani

Thank you so much Rohit.

Your help is always greatly appreciated

POSTED BY: M.A. Ghorbani
Posted 6 years ago

Hi Mohammad,

To remove the empty strings

list1 = Association[Rule @@@ Partition[Extract[m, {{1, 1}, {2}, {6, 1}, {7}}], 2]] // 
          Map[DeleteCases[#, ""] &]
POSTED BY: Rohit Namjoshi
POSTED BY: M.A. Ghorbani
Posted 6 years ago

A neat solution. Thank you Gustavo.

POSTED BY: Alex Teymouri
POSTED BY: Henrik Schachner
POSTED BY: Gustavo Delfino

That is a great, Henrik.

i appreciate your time and consideration.

POSTED BY: M.A. Ghorbani

I guess you basically want TimelinePlot. If the diagram does not have to look exactly like the one shown (which is not very obvious anyway!), as a first try you can do like so:

list1 = Association[Rule @@@ Partition[Extract[list, {{1, 1}, {2}, {6, 1}, {7}}], 2]];
minmax = MinMax /@ list1;
list2 = Interval /@ Map[DateObject@*ToString, minmax, {2}];
tlp = TimelinePlot[list2, ImageSize -> {400, 100}];
Grid[{{TableForm[KeyValueMap[List, minmax], TableHeadings -> {None, {"City", "Date"}}, TableDepth -> 2], tlp}}, Frame -> All]

enter image description here

EDIT: Here a minor improvement (for the last line):

Grid[{{TableForm[
    KeyValueMap[
     List, #1 ~~ " - " ~~ #2 & @@@ 
      Map[StringDelete["."]@*ToString, minmax, {2}]], 
    TableHeadings -> {None, {"City", "Date"}}, TableDepth -> 2], 
   tlp}}, Frame -> All]

enter image description here

POSTED BY: Henrik Schachner

Hi Werner,

The first point is start of the date (1990) and the last point is end of the date(1996).

Thank you

POSTED BY: M.A. Ghorbani
Posted 6 years ago

Which data do you want to show in the third column?

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