MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Multi-Colored Filling in DateListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104147] Re: Multi-Colored Filling in DateListPlot
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Wed, 21 Oct 2009 06:29:09 -0400 (EDT)
  • References: <200910191114.HAA02303@smc.vnet.net> <hbju2s$67m$1@smc.vnet.net>

On Oct 20, 3:58 am, Mark McClure <mcmcc... at unca.edu> wrote:
> On Mon, Oct 19, 2009 at 7:14 AM, jroge <jr... at mac.com> wrote:
> > I am working on developing some financial reports and I have gotten
> > stuck on using multiple colors in the filling of a DateListPlot. I
> > would like to have the color of the filling alternate between blue and
> > pink each quarter (or year depending on the plot) rather than a single
> > color in the entire filling.
>
> How's this:
> date = {2008, 1};
> duration = 16;
> data = Table[FinancialData["GE",
>   {date, date = DatePlus[date, {1, "Month"}]}],
>   {duration}];
> data = Append[Append[#[[1]], #[[2, 1]]] & /@
>   Partition[data, 2, 1], Last[data]];
> DateListPlot[data, Joined -> True,
>   Filling -> Table[i -> {Bottom,
>     If[EvenQ[i], RGBColor[1, 0, 0, 0.5],
>   RGBColor[0, 0, 1, 0.5]]},
>   {i, 1, duration}]]
>
> The redefinition of data just makes things line up a
> little nicer.  You can delete that line to see what I
> mean.
>
> Hope that helps,
> Mark McClure

ok here is another attempt:

Clear[splitList, bandedDateListPlot];

splitList[data_List, division_String] := Module[{tmp, tmp1, tmp2},
   tmp = DateString[#1, division] & /@ data[[All, 1]];
   tmp1 = Accumulate[Length /@ Split[tmp]];
   tmp2 = Partition[Flatten[{1, Most[tmp1] + 1, Last[tmp1]}], 2, 1]
   ];


bandedDateListPlot[data_List, division_String,
   opts : OptionsPattern[]] := Module[{divisions, newData, len},
   divisions = splitList[data, division];
   newData = Take[data, #] & /@ divisions;
   len = Length[newData];

   DateListPlot[newData,
    Joined -> True,
    Filling -> Flatten[{# -> Bottom, # -> Top} & /@ Range[len], 1],
    FillingStyle ->
     Flatten[If[
         OddQ[#], # -> {RGBColor[0.8784, 0.8784, 0.8784],
           RGBColor[0.7294, 0.788, 0.906]}, # -> {RGBColor[0.9412,
            0.9412, 0.9412], RGBColor[0.2980, 0.5098, 0.7647]}] & /@
       Range[len], 1],
    PlotStyle -> {{RGBColor[0, 0.4, 0.702], Thick}},
    opts]
   ];

ge = FinancialData["GE", "Feb. 16, 2007"];

bandedDateListPlot[ge, "Quarter", PlotRangePadding -> 0]

Mike


  • Prev by Date: Re: Re: How to find which variable caused the trigger in Manipulate[]
  • Next by Date: Re: Question on Dynamic with "DockedCell"
  • Previous by thread: Re: Multi-Colored Filling in DateListPlot
  • Next by thread: Re: Multi-Colored Filling in DateListPlot