Message Boards Message Boards

0
|
8939 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

Another option is using NumberLinePlot

With[{opts={Ticks->None,Axes->False,AxesStyle->White,PlotRange->{{1990,2000},Automatic}}},
  Grid[
    {{"City","Date",""},
     {Item["Washington",Alignment->Left],"1990-1996",NumberLinePlot[Style[Interval[{1990,1996}],Red],opts]},
     {Item["Texas",Alignment->Left],"1994-2000",NumberLinePlot[Style[Interval[{1994,2000}],Darker@Green],opts]}},
    Dividers->{{None,Black,Black},{None,Black}}]]

grid

POSTED BY: Gustavo Delfino

@Gustavo Delfino: NumberLinePlot[Style[Interval[{...}] - Nice solution, I definitely like it!

POSTED BY: Henrik Schachner
Posted 4 years ago

A neat solution. Thank you Gustavo.

POSTED BY: Alex Teymouri

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

That is a great, Henrik.

i appreciate your time and consideration.

POSTED BY: M.A. Ghorbani

Hi Henrik,

Sometimes there are empty spaces on the list when I import the data from Excel.I couldn't delete these empty spaces using the DeleteCase[m," "] or DeleteCase[m,Null]. Is there any way to get rid of this problem?

In[22]:= m = {{"ACIPAYAM", "ACIPAYAM", "ACIPAYAM", "ACIPAYAM", "", 
    ""}, {"1966", "1966", "1966", "1966", "", ""}, {"2", "3", "4", 
    "5", "", ""}, {"19.5", "61.1", "17.2", "56.1", "", ""}, {"", 
    ""}, {"ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", 
    "ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", 
    "ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", "ADANA BÖLGE", "", 
    ""}, {"1930", "1930", "1930", "1930", "1930", "1930", "1930", 
    "1930", "1930", "1930", "1930", "1930", "", ""}, {"1", "2", "3", 
    "4", "5", "6", "7", "8", "9", "10", "11", "12", "", ""}, {"29.4", 
    "58.6", "50.7", "56.4", "30.0", "37.5", "35.2", "23.2", "33.0", 
    "49.2", "80.9", "188.2", "", ""}};

In[23]:= list1 = 
 Association[
  Rule @@@ Partition[Extract[m, {{1, 1}, {2}, {6, 1}, {7}}], 2]]

Out[23]= <|"ACIPAYAM" -> {"1966", "1966", "1966", "1966", "", ""}, 
 "ADANA BÖLGE" -> {"1930", "1930", "1930", "1930", "1930", "1930", 
   "1930", "1930", "1930", "1930", "1930", "1930", "", ""}|>

In[24]:= minmax = MinMax /@ list1

Out[24]= <|"ACIPAYAM" -> {Min["", "1966"], Max["", "1966"]}, 
 "ADANA BÖLGE" -> {Min["", "1930"], Max["", "1930"]}|>

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

Out[25]= <|"ACIPAYAM" -> 
  Interval[{DateObject[{1966}, "Year", "Gregorian", 3.5], 
    DateObject[{1966}, "Year", "Gregorian", 3.5]}], 
 "ADANA BÖLGE" -> 
  Interval[{DateObject[{1930}, "Year", "Gregorian", 3.5], 
    DateObject[{1930}, "Year", "Gregorian", 3.5]}]|>

In[26]:= tlp = TimelinePlot[list2, ImageSize -> {400, 100}]
POSTED BY: M.A. Ghorbani
Posted 4 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

Thank you so much Rohit.

Your help is always greatly appreciated

POSTED BY: M.A. Ghorbani

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
Posted 4 years ago

Hi Mohammad,

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

POSTED BY: Rohit Namjoshi

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

Why not simply

DeleteCases[#, ""] & /@ m

?

POSTED BY: Hans Dolhaine

Thank you, Henrik and Rohit,

I got an error when I used the command for my main data. Where am I wrong?

In[35]:= list1 = <|"ACIPAYAM" -> {"1966", "1966", "1966", "1966", 
     "1966", "1966", "1966", "1966", "1966", "1967", "1967", "1967", 
     "1967", "1967", "1967", "1967", "1967", "1967", "1967", "1967", 
     "1967", "1967", "1968", "1968", "1968", "1968", "1968", "1968", 
     "1968", "1968", "1968", "1968", "1968", "1968", "1969", "1969", 
     "1969", "1969", "1969", "1969", "1969", "1969", "1969", "1969", 
     "1969", "1969", "1969", "1970", "1970", "1970", "1970", "1970", 
     "1970", "1970", "1970", "1970", "1970", "1970", "1970", "1970", 
     "1971", "1971", "1971", "1971", "1971", "1971", "1971", "1971", 
     "1971", "1971", "1971", "1971", "1971", "1972", "1972", "1972", 
     "1972", "1972", "1972", "1972", "1972", "1972", "1972", "1972", 
     "1972", "1972", "1973", "1973", "1973", "1973", "1973", "1973", 
     "1973", "1973", "1973", "1973", "1973", "1973", "1974", "1974", 
     "1974", "1974", "1974", "1974", "1974", "1974", "1974", "1974", 
     "1974", "1974", "1975", "1975", "1975", "1975", "1975", "1975", 
     "1975", "1975", "1975", "1975", "1975", "1975", "1975", "1976", 
     "1976", "1976", "1976", "1976", "1976", "1976", "1976", "1976", 
     "1976", "1976", "1976", "1977", "1977", "1979", "1979", "1979", 
     "1979", "1979", "1979", "1979", "1979", "1979", "1979", "1979", 
     "1979", "1979", "1980", "1980", "1980", "1980", "1980", "1980", 
     "1980", "1980", "1980", "1980", "1980", "1980", "1981", "1981", 
     "1981", "1981", "1981", "1981", "1981", "1981", "1981", "1981", 
     "1981", "1981", "1981", "1982", "1982", "1982", "1982", "1982", 
     "1982", "1982", "1982", "1982", "1982", "1982", "1982", "1982", 
     "1983", "1983", "1983", "1983", "1983", "1983", "1983", "1983", 
     "1983", "1983", "1983", "1983", "1983", "1984", "1984", "1984", 
     "1984", "1984", "1984", "1984", "1984", "1984", "1984", "1984", 
     "1984", "1985", "1985", "1985", "1985", "1985", "1985", "1985", 
     "1985", "1985", "1985", "1985", "1985", "1986", "1986", "1986", 
     "1986", "1986", "1986", "1986", "1986", "1986", "1986", "1986", 
     "1986", "1986", "1987", "1987", "1987", "1987", "1987", "1987", 
     "1987", "1987", "1987", "1987", "1987", "1987", "1988", "1988", 
     "1988", "1988", "1988", "1988", "1988", "1988", "1988", "1988", 
     "1988", "1988", "1988", "1989", "1989", "1989", "1989", "1989", 
     "1989", "1989", "1989", "1989", "1989", "1989", "1990", "1990", 
     "1990", "1990", "1990", "1990", "1990", "1990", "1990", "1990", 
     "1990", "1990", "1991", "1991", "1991", "1991", "1991", "1991", 
     "1991", "1991", "1991", "1991", "1991", "1991", "1991", "1992", 
     "1992", "1992", "1992", "1992", "1992", "1992", "1992", "1992", 
     "1992", "1992", "1993", "1993", "1993", "1993", "1993", "1993", 
     "1993", "1993", "1993", "1993", "1993", "1994", "1994", "1994", 
     "1994", "1994", "1994", "1994", "1994", "1994", "1994", "1994", 
     "1994", "1994", "1995", "1995", "1995", "1995", "1995", "1995", 
     "1995", "1995", "1995", "1995", "1995", "1995", "1996", "1996", 
     "1996", "1996", "1996", "1996", "1996", "1996", "1996", "1996", 
     "1996", "1996", "1997", "1997", "1997", "1997", "1997", "1997", 
     "1997", "1997", "1997", "1997", "1997", "1997", "1998", "1998", 
     "1998", "1998", "1998", "1998", "1998", "1998", "1998", "1998", 
     "1998", "1998", "1999", "1999", "1999", "1999", "1999", "1999", 
     "1999", "1999", "1999", "1999", "1999", "1999", "1999", "2000", 
     "2000", "2000", "2000", "2000", "2000", "2000", "2000", "2000", 
     "2000", "2000", "2000", "2000", "2001", "2001", "2001", "2001", 
     "2001", "2001", "2001", "2001", "2001", "2001", "2001", "2001", 
     "2001", "2002", "2002", "2002", "2002", "2002", "2002", "2002", 
     "2002", "2002", "2002", "2002", "2002", "2002", "2003", "2003", 
     "2003", "2003", "2003", "2003", "2003", "2003", "2003", "2003", 
     "2003", "2004", "2004", "2004", "2004", "2004", "2004", "2004", 
     "2004", "2004", "2004", "2004", "2004", "2004", "2005", "2005", 
     "2005", "2005", "2005", "2005", "2005", "2005", "2005", "2005", 
     "2005", "2005", "2005", "2006", "2006", "2006", "2006", "2006", 
     "2006", "2006", "2006", "2006", "2006", "2006", "2006", "2006", 
     "2007", "2007", "2007", "2007", "2007", "2007", "2007", "2007", 
     "2007", "2007", "2007", "2007", "2008", "2008", "2008", "2008", 
     "2008", "2008", "2008", "2008", "2008", "2008", "2008", "2008", 
     "2008", "2009", "2009", "2009", "2009", "2009", "2009", "2009", 
     "2009", "2009", "2009", "2009", "2009", "2009", "2010", "2010", 
     "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", 
     "2010", "2010", "2010", "2011", "2011", "2011", "2011", "2011", 
     "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2012", 
     "2012"}, 
   "ADANA BÖLGE" -> {"1930", "1930", "1930", "1930", "1930", "1930", 
     "1930", "1930", "1930", "1930", "1930", "1930", "1930", "1931", 
     "1931", "1931", "1931", "1931", "1931", "1931", "1931", "1931", 
     "1931", "1931", "1931", "1931", "1932", "1932", "1932", "1932", 
     "1932", "1932", "1932", "1932", "1932", "1932", "1932", "1933", 
     "1933", "1933", "1933", "1933", "1933", "1933", "1933", "1933", 
     "1933", "1933", "1934", "1934", "1934", "1934", "1934", "1934", 
     "1934", "1934", "1934", "1934", "1934", "1934", "1935", "1935", 
     "1935", "1935", "1935", "1935", "1935", "1935", "1935", "1935", 
     "1935", "1935", "1935", "1936", "1936", "1936", "1936", "1936", 
     "1936", "1936", "1936", "1936", "1936", "1936", "1936", "1936", 
     "1937", "1937", "1937", "1937", "1937", "1937", "1937", "1937", 
     "1937", "1937", "1938", "1938", "1938", "1938", "1938", "1938", 
     "1938", "1938", "1938", "1938", "1938", "1938", "1939", "1939", 
     "1939", "1939", "1939", "1939", "1939", "1939", "1939", "1939", 
     "1939", "1940", "1940", "1940", "1940", "1940", "1940", "1940", 
     "1940", "1940", "1940", "1940", "1941", "1941", "1941", "1941", 
     "1941", "1941", "1941", "1941", "1941", "1941", "1941", "1941", 
     "1942", "1942", "1942", "1942", "1942", "1942", "1942", "1942", 
     "1942", "1942", "1942", "1942", "1942", "1943", "1943", "1943", 
     "1943", "1943", "1943", "1943", "1943", "1943", "1943", "1944", 
     "1944", "1944", "1944", "1944", "1944", "1944", "1944", "1944", 
     "1944", "1944", "1944", "1945", "1945", "1945", "1945", "1945", 
     "1945", "1945", "1945", "1945", "1945", "1946", "1946", "1946", 
     "1946", "1946", "1946", "1946", "1946", "1946", "1946", "1946", 
     "1947", "1947", "1947", "1947", "1947", "1947", "1947", "1947", 
     "1947", "1947", "1947", "1947", "1948", "1948", "1948", "1948", 
     "1948", "1948", "1948", "1948", "1948", "1948", "1948", "1948", 
     "1948", "1949", "1949", "1949", "1949", "1949", "1949", "1949", 
     "1949", "1949", "1949", "1949", "1949", "1950", "1950", "1950", 
     "1950", "1950", "1950", "1950", "1950", "1950", "1950", "1950", 
     "1950", "1951", "1951", "1951", "1951", "1951", "1951", "1951", 
     "1951", "1951", "1951", "1951", "1951", "1952", "1952", "1952", 
     "1952", "1952", "1952", "1952", "1952", "1952", "1952", "1952", 
     "1952", "1952", "1953", "1953", "1953", "1953", "1953", "1953", 
     "1953", "1953", "1953", "1953", "1953", "1953", "1954", "1954", 
     "1954", "1954", "1954", "1954", "1954", "1954", "1954", "1954", 
     "1954", "1955", "1955", "1955", "1955", "1955", "1955", "1955", 
     "1955", "1955", "1955", "1955", "1955", "1955", "1956", "1956", 
     "1956", "1956", "1956", "1956", "1956", "1956", "1956", "1956", 
     "1956", "1956", "1958", "1958", "1958", "1958", "1958", "1958", 
     "1958", "1958", "1958", "1958", "1958", "1958", "1958", "1959", 
     "1959", "1959", "1959", "1959", "1959", "1959", "1959", "1959", 
     "1959", "1959", "1959", "1959", "1960", "1960", "1960", "1960", 
     "1960", "1960", "1960", "1960", "1960", "1960", "1960", "1960", 
     "1960", "1961", "1961", "1961", "1961", "1961", "1961", "1961", 
     "1961", "1961", "1961", "1961", "1962", "1962", "1962", "1962", 
     "1962", "1962", "1962", "1962", "1962", "1962", "1962", "1963", 
     "1963", "1963", "1963", "1963", "1963", "1963", "1963", "1963", 
     "1963", "1963", "1963", "1964", "1964", "1964", "1964", "1964", 
     "1964", "1964", "1964", "1964", "1964", "1964", "1965", "1965", 
     "1965", "1965", "1965", "1965", "1965", "1965", "1965", "1965", 
     "1965", "1965", "1965", "1966", "1966", "1966", "1966", "1966", 
     "1966", "1966", "1966", "1966", "1966", "1966", "1966", "1966", 
     "1967", "1967", "1967", "1967", "1967", "1967", "1967", "1967", 
     "1967", "1967", "1967", "1967", "1968", "1968", "1968", "1968", 
     "1968", "1968", "1968", "1968", "1968", "1968", "1968", "1968", 
     "1968", "1969", "1969", "1969", "1969", "1969", "1969", "1969", 
     "1969", "1969", "1969", "1969", "1970", "1970", "1970", "1970", 
     "1970", "1970", "1970", "1970", "1970", "1970", "1970", "1970", 
     "1970", "1971", "1971", "1971", "1971", "1971", "1971", "1971", 
     "1971", "1971", "1971", "1971", "1971", "1971", "1972", "1972", 
     "1972", "1972", "1972", "1972", "1972", "1972", "1972", "1972", 
     "1972", "1973", "1973", "1973", "1973", "1973", "1973", "1973", 
     "1973", "1973", "1973", "1973", "1974", "1974", "1974", "1974", 
     "1974", "1974", "1974", "1974", "1974", "1974", "1974", "1975", 
     "1975", "1975", "1975", "1975", "1975", "1975", "1975", "1975", 
     "1975", "1975", "1975", "1976", "1976", "1976", "1976", "1976", 
     "1976", "1976", "1976", "1976", "1976", "1976", "1976", "1976", 
     "1977", "1977", "1977", "1977", "1977", "1977", "1977", "1977", 
     "1977", "1977", "1977", "1977", "1978", "1978", "1978", "1978", 
     "1978", "1978", "1978", "1978", "1978", "1978", "1978", "1979", 
     "1979", "1979", "1979", "1979", "1979", "1979", "1979", "1979", 
     "1979", "1979", "1979", "1980", "1980", "1980", "1980", "1980", 
     "1980", "1980", "1980", "1980", "1980", "1980", "1981", "1981", 
     "1981", "1981", "1981", "1981", "1981", "1981", "1981", "1981", 
     "1981", "1982", "1982", "1982", "1982", "1982", "1982", "1982", 
     "1982", "1982", "1982", "1982", "1982", "1982", "1983", "1983", 
     "1983", "1983", "1983", "1983", "1983", "1983", "1983", "1983", 
     "1983", "1983", "1983", "1984", "1984", "1984", "1984", "1984", 
     "1984", "1984", "1984", "1984", "1984", "1984", "1984", "1985", 
     "1985", "1985", "1985", "1985", "1985", "1985", "1985", "1985", 
     "1985", "1985", "1986", "1986", "1986", "1986", "1986", "1986", 
     "1986", "1986", "1986", "1986", "1986", "1987", "1987", "1987", 
     "1987", "1987", "1987", "1987", "1987", "1987", "1987", "1987", 
     "1987", "1988", "1988", "1988", "1988", "1988", "1988", "1988", 
     "1988", "1988", "1988", "1988", "1989", "1989", "1989", "1989", 
     "1989", "1989", "1989", "1989", "1989", "1989", "1990", "1990", 
     "1990", "1990", "1990", "1990", "1990", "1990", "1990", "1990", 
     "1990", "1990", "1990", "1991", "1991", "1991", "1991", "1991", 
     "1991", "1991", "1991", "1991", "1991", "1991", "1991", "1991", 
     "1992", "1992", "1992", "1992", "1992", "1992", "1992", "1992", 
     "1992", "1992", "1992", "1992", "1993", "1993", "1993", "1993", 
     "1993", "1993", "1993", "1993", "1993", "1993", "1994", "1994", 
     "1994", "1994", "1994", "1994", "1994", "1994", "1994", "1994", 
     "1994", "1994", "1994", "1995", "1995", "1995", "1995", "1995", 
     "1995", "1995", "1995", "1995", "1995", "1995", "1995", "1996", 
     "1996", "1996", "1996", "1996", "1996", "1996", "1996", "1996", 
     "1996", "1996", "1996", "1997", "1997", "1997", "1997", "1997", 
     "1997", "1997", "1997", "1997", "1997", "1997", "1997", "1997", 
     "1998", "1998", "1998", "1998", "1998", "1998", "1998", "1998", 
     "1998", "1998", "1998", "1998", "1999", "1999", "1999", "1999", 
     "1999", "1999", "1999", "1999", "1999", "1999", "1999", "1999", 
     "1999", "2000", "2000", "2000", "2000", "2000", "2000", "2000", 
     "2000", "2000", "2000", "2001", "2001", "2001", "2001", "2001", 
     "2001", "2001", "2001", "2001", "2001", "2001", "2002", "2002", 
     "2002", "2002", "2002", "2002", "2002", "2002", "2002", "2002", 
     "2002", "2002", "2002", "2003", "2003", "2003", "2003", "2003", 
     "2003", "2003", "2003", "2003", "2003", "2003", "2003", "2004", 
     "2004", "2004", "2004", "2004", "2004", "2004", "2004", "2004", 
     "2004", "2004", "2005", "2005", "2005", "2005", "2005", "2005", 
     "2005", "2005", "2005", "2005", "2005", "2005", "2005", "2006", 
     "2006", "2006", "2006", "2006", "2006", "2006", "2006", "2006", 
     "2006", "2006", "2007", "2007", "2007", "2007", "2007", "2007", 
     "2007", "2007", "2007", "2007", "2007", "2007", "2008", "2008", 
     "2008", "2008", "2008", "2008", "2008", "2008", "2008", "2008", 
     "2008", "2008", "2009", "2009", "2009", "2009", "2009", "2009", 
     "2009", "2009", "2009", "2009", "2009", "2010", "2010", "2010", 
     "2010", "2010", "2010", "2010", "2010", "2010", "2010", "2010", 
     "2011", "2011", "2011", "2011", "2011", "2011", "2011", "2011", 
     "2011", "2011", "2011", "2012", "2012", "2012", "2012", "2012", 
     "2012", "2012", "2012", "2012", "2012", "2012", "2012", "2013", 
     "2013", "2013", "2013", "2013", "2013", "2013", "2013", "2013", 
     "2013", "2013", "2013", "2014", "2014", "2014", "2014", "2014", 
     "2014", "2014", "2014", "2014", "2014", "2014", "2014", "2014", 
     "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", 
     "2015", "2015", "2015", "2015", "2015", "2016", "2016", "2016", 
     "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", 
     "2016", "2017", "2017", "2017", "2017", "2017", "2017", "2017", 
     "2017", "2017", "2017", "2017", "2018", "2018", "2018", "2018", 
     "2018", "2018", "2018", "2018", "2018", "2018"}|>;

In[36]:= minmax = MinMax /@ list1

Out[36]= <|"ACIPAYAM" -> {Min["1966", "1967", "1968", "1969", "1970", 
    "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1979", 
    "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", 
    "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", 
    "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", 
    "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", 
    "2012"], 
   Max["1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973",
     "1974", "1975", "1976", "1977", "1979", "1980", "1981", "1982", 
    "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", 
    "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", 
    "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", 
    "2007", "2008", "2009", "2010", "2011", "2012"]}, 
 "ADANA BÖLGE" -> {Min["1930", "1931", "1932", "1933", "1934", "1935",
     "1936", "1937", "1938", "1939", "1940", "1941", "1942", "1943", 
    "1944", "1945", "1946", "1947", "1948", "1949", "1950", "1951", 
    "1952", "1953", "1954", "1955", "1956", "1958", "1959", "1960", 
    "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", 
    "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", 
    "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", 
    "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", 
    "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", 
    "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", 
    "2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016", 
    "2017", "2018"], 
   Max["1930", "1931", "1932", "1933", "1934", "1935", "1936", "1937",
     "1938", "1939", "1940", "1941", "1942", "1943", "1944", "1945", 
    "1946", "1947", "1948", "1949", "1950", "1951", "1952", "1953", 
    "1954", "1955", "1956", "1958", "1959", "1960", "1961", "1962", 
    "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", 
    "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", 
    "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", 
    "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", 
    "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", 
    "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", 
    "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018"]}|>

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

During evaluation of In[38]:= DateObject::str: String Min[1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012] cannot be interpreted as a date.

During evaluation of In[38]:= DateObject::str: String Max[1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012] cannot be interpreted as a date.

During evaluation of In[38]:= DateObject::str: String Min[1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018] cannot be interpreted as a date.

During evaluation of In[38]:= General::stop: Further output of DateObject::str will be suppressed during this calculation.

Out[38]= <|"ACIPAYAM" -> 
  Interval[{DateObject[
     "Min[1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, \
1976, 1977, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, \
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, \
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, \
2010, 2011, 2012]"], 
    DateObject[
     "Max[1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, \
1976, 1977, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, \
1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, \
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, \
2010, 2011, 2012]"]}], 
 "ADANA BÖLGE" -> 
  Interval[{DateObject[
     "Min[1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, \
1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, \
1951, 1952, 1953, 1954, 1955, 1956, 1958, 1959, 1960, 1961, 1962, \
1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, \
1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, \
1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, \
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, \
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, \
2018]"], DateObject[
     "Max[1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, \
1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, \
1951, 1952, 1953, 1954, 1955, 1956, 1958, 1959, 1960, 1961, 1962, \
1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, \
1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, \
1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, \
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, \
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, \
2018]"]}]|>
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

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
Posted 4 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

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 4 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

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 4 years ago

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

POSTED BY: Werner Geiger

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
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