1
$\begingroup$

I have list such as

list = {1, 5, 2, 6, 3,...}

and I need to plot the numbers from the list on a horizontal line such that there will be on a place on horizontal line which will correspond to the number itself plus all the previous numbers.

Using the above-mentioned list:

1 will be plotted at the place of number 1; 5 will be plotted at the place of number 6; 2 will be plotted at the place of number 8; 6 will be plotted at the place of number 14 etc.

$\endgroup$

2 Answers 2

2
$\begingroup$
list = {1, 5, 2, 6, 3};
NumberLinePlot[list]

enter image description here

NumberLinePlot[Accumulate@list]

enter image description here

ListPlot[Transpose[{list,Accumulate@list}]]

enter image description here

Update:

... on the horizontal axis, there would be instead of accumulated numbers, dates that correspond to to the accumulated number

... in case of one graph ... there are selected months on the horizontal.

list2 = RandomInteger[100, 50]; DateListPlot[
 Transpose[{DayPlus[{1999, 1, 2}, #] & /@ Accumulate@list2, list2}], 
 FrameTicks -> {{{2000, 1}, {2001, 4}, {2002, 2}, {2002, 11}, 
    {2003, 7}, {2003, 12}, {2004, 8}}, Automatic, Automatic, Automatic}, 
 DateTicksFormat -> {"MonthName", "\n", "Year"}, ImageSize -> 600, 
 AspectRatio -> 1/4]

enter image description here

$\endgroup$
10
  • $\begingroup$ Awesome, @kguler. You also made me realize that plot it in 2D will be better. Can I also ask you whether it can be done that on the horizontal axis, there would be instead of accumulated numbers, dates that correspond to to the accumulated number -> I have also a list of DateObjects -> e.g. if the accumulated number equals to 6, the date that is within 6 days from the first day in a list will appear on a horizontal line (or better, only just few of such a dates will appear otherwise it would not be possible to read it $\endgroup$ Apr 16, 2015 at 19:49
  • $\begingroup$ @rabbit, maybe something like: DateListPlot[List/@Transpose[{DayPlus[Today,#]&/@Accumulate@list,list}],PlotMarkers->(Style[#,20]&/@list),ImageSize->500]? $\endgroup$
    – kglr
    Apr 16, 2015 at 20:57
  • $\begingroup$ which list in your code is the list with DateObjects (since I have the dates in separate list)? ...or maybe it would also suffice to add the dates manuály such as {{1999, 1, 2},{2000, 1, 2}}. $\endgroup$ Apr 17, 2015 at 6:13
  • $\begingroup$ @rabbit3698741, DayPlus[Today,#]&/@Accumulate@list. $\endgroup$
    – kglr
    Apr 17, 2015 at 6:29
  • $\begingroup$ OK so i tried DateListPlot[ List /@ Transpose[{DayPlus[{1999, 1, 2}, #] & /@ Accumulate@list, list}], PlotMar‌​kers -> (Style[#, 20]&/@list), ImageSize -> 500], where list is the same list as mentioned in your main answer and it returns me: Unknown option PlotMar‌​kers... @kguler $\endgroup$ Apr 17, 2015 at 7:50
4
$\begingroup$
list = {1, 5, 2, 6, 3};
ListPlot[{#} & /@ 
  Transpose[{Accumulate[list], Table[1, {Length[list]}]}], 
 PlotMarkers -> list, Axes -> {True, False}, AspectRatio -> 1/10]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ thanks! It also works. However, I realized that the solution given by kguler will be more appropriate for my needs @shrx. $\endgroup$ Apr 17, 2015 at 7:55
  • $\begingroup$ @rabbit3698741 no problem, although I think my solution is more relevant to what you are asking. You should consider this when you decide to accept an answer (you can accept only one). $\endgroup$
    – shrx
    Apr 17, 2015 at 12:46

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.