From: Armand Tamzarian on
On Oct 20, 3:58 am, Mark McClure <mcmcc...(a)unca.edu> wrote:
> On Mon, Oct 19, 2009 at 7:14 AM, jroge <jr...(a)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

From: jroge on
On Oct 20, 1:49 am, Armand Tamzarian <mike.honeychu...(a)gmail.com>
wrote:
> On Oct 19, 6:11=C2 am, jroge <jr...(a)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. Here is an example of what I am trying to
> > do:
>
> >http://online.wsj.com/article/SB125479559237566623.html
>
> > I suspect that FillingStyle is the function I need to use, but calling
> > out each quarter's (or year's) data is beyond me. Any thoughts? I have
> > been using a fairly generic plot of GE stock data for exploration:
>
> > DateListPlot[FinancialData["GE", "Jan. 1, 2008"], Joined -> True,
> > Filling -> Bottom]
>
> > Thanks,
>
> > Jroge
>
> I saw a blog post that describes how to do this:
>
> http://wildebeests.wordpress.com/2009/08/16/creating-highlighting-ban...
>
> Easiest way is to split your data into separate lists for periods you
> want shaded eg. months, quarters etc.
>
> DateListPlot[{month1,month2,month3 ...}, Filling{Filling=E2=86=92{{=
1=E2=86=
> =92Bottom},
> {1=E2=86=92Top}, {2=E2=86=92Bottom}, {2=E2=86=92Top},=
=E2=80=A6}]
>
> Mike

This isn't quite what i was looking to do, but what the author
describes in his blog post is also quite useful. Thank you for sending.

From: jroge on
On Oct 20, 1:55 am, "David Park" <djmp...(a)comcast.net> wrote:
> One way to do this is with the Presentations package.
>
> Needs["Presentations`Master`"]
>
> Write routines to generate DateListPlot date iterators for each quarter o=
ver
> a span of years.
>
> Q1Iter[year1_, year2_] :=
> Table[{"Jan 1, " <> ToString[year],
> "Mar 31, " <> ToString[year]}, {year, year1, year2}]
> Q2Iter[year1_, year2_] :=
> Table[{"Apr 1, " <> ToString[year],
> "Jun 30, " <> ToString[year]}, {year, year1, year2}]
> Q3Iter[year1_, year2_] :=
> Table[{"Jul 1, " <> ToString[year],
> "Sep 30, " <> ToString[year]}, {year, year1, year2}]
> Q4Iter[year1_, year2_] :=
> Table[{"Oct 1, " <> ToString[year],
> "Dec 31, " <> ToString[year]}, {year, year1, year2}]
>
> Then just draw the quarters with their separate filling color. Use
> CustomDateTicks to label the time axis.
>
> dateticks =
> CustomDateTicks[{{2005, 1, 1}, {2010, 1, 1}, {1, "Year"}, 4},
> DateString[#, {"Year"}] &];
>
> Draw2D[
> {DateListDraw[FinancialData["GE", #],
> AxesOrigin -> {Automatic, 0},
> Filling -> Axis,
> FillingStyle -> Lighter(a)Blue,
> Joined -> True] & /@ Join[Q1Iter[2005, 2009], Q3Iter[2005, 200=
9]],
> DateListDraw[FinancialData["GE", #],
> AxesOrigin -> {Automatic, 0},
> Filling -> Axis,
> FillingStyle -> Lighter(a)Red,
> Joined -> True] & /@ Join[Q2Iter[2005, 2009], Q4Iter[2005, 200=
8]]
> },
> AspectRatio -> .3,
> Frame -> True,
> FrameTicks -> {{Automatic, Automatic}, {dateticks,
> dateticks // NoTickLabels}},
> PlotLabel -> Style["GE Stock Price", 14, Bold],
> ImageSize -> 500]
>
> David Park
> djmp...(a)comcast.nethttp://home.comcast.net/~djmpark/
>
> From: jroge [mailto:jr...(a)mac.com]
>
> 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. Here is an example of what I am trying to
> do:
>
> http://online.wsj.com/article/SB125479559237566623.html
>
> I suspect that FillingStyle is the function I need to use, but calling
> out each quarter's (or year's) data is beyond me. Any thoughts? I have
> been using a fairly generic plot of GE stock data for exploration:
>
> DateListPlot[FinancialData["GE", "Jan. 1, 2008"], Joined -> True,
> Filling -> Bottom]
>
> Thanks,
>
> Jroge

David:

The presentations package certainly works. It does result in a white
line between some of the quarters. Also, that white line is thicker
between some quarters and others. Is that an out put or display issue
on my system or something that should be adjusted in the code?

From: jroge on
On Oct 19, 4:11 am, jroge <jr...(a)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. Here is an example of what I am trying to
> do:
>
> http://online.wsj.com/article/SB125479559237566623.html
>
> I suspect that FillingStyle is the function I need to use, but calling
> out each quarter's (or year's) data is beyond me. Any thoughts? I have
> been using a fairly generic plot of GE stock data for exploration:
>
> DateListPlot[FinancialData["GE", "Jan. 1, 2008"], Joined -> True,
> Filling -> Bottom]
>
> Thanks,
>
> Jroge

Thank's everyone for responding. All of the suggested solutions work.
I really appreciate seeing the different ways to approaching this.