Prev: Push to clipboard?
Next: Assumptions, Abs, etc.
From: Dan Loewenherz on 6 Jun 2010 06:41 Hi all, I'm trying to use some Graphics elements as markers for data points in my DateListPlot. I'm running into an issue where the first element of the PlotMarker list is being superimposed on every point in the plot. Here is the code which returns similarly undesired behavior. Instead of letters, I'm using points. Nonetheless, the problem is the same. The desired behavior is for the points to scale to the values of HourlyDataPointCount. --------8<-------- HourlyAverageCost = {186.8235294117647, 153.28722772277229, 148.25412844036697, 147.67576719576721, 148.1043396226415, 147.34375, 142.72424242424245, 141.44635627530366, 152.81413333333333, 151.30989583333334, 153.04958677685951, 153.12459893048128, 163.7921212121212, 184.74429223744292, 177.25316455696202, 140.55072463768116, 215.27272727272728, 149.90322580645162, 138.625, 94.0, 0, 140.0625, 142.44230769230768}; HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; Points = Map[ Graphics[{PointSize[Log[#/10 + 0.001]], Point[{0, 0}]}] &, HourlyDataPointCount] DateListPlot[Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, Frame -> False, PlotRange -> {Automatic, {0, 350}}, PlotMarkers -> Points] -------->8-------- Thanks in advance, Dan
From: Bob Hanlon on 7 Jun 2010 08:06 If you want each point to have its own style then each point must be a separate list, i.e., Map List onto the data. HourlyAverageCost = { 186.8, 153.3, 148.3, 147.7, 148.1, 147.3, 142.7, 141.4, 152.8, 151.3, 153.0, 153.1, 163.8, 184.7, 177.3, 140.6, 215.3, 149.9, 138.6, 94.0, 0, 140.1, 142.4}; HourlyDataPointCount = { 17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[ DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; Points = Map[Graphics[ {AbsolutePointSize[#/18 + 1], Point[{0, 0}]}] &, HourlyDataPointCount]; DateListPlot[ List /@ Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, LabelStyle -> Directive[ FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> Black, Frame -> False, PlotRange -> {Automatic, {0, 350}}, PlotMarkers -> Points] Or just using PlotStyle rather than PlotMarkers DateListPlot[ List /@ Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, LabelStyle -> Directive[ FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> (Directive[Black, AbsolutePointSize[#]] & /@ (28*Rescale[HourlyDataPointCount] + 1)), Frame -> False, PlotRange -> {Automatic, {0, 350}}] Bob Hanlon ---- Dan Loewenherz <dloewenherz(a)gmail.com> wrote: ============= Hi all, I'm trying to use some Graphics elements as markers for data points in my DateListPlot. I'm running into an issue where the first element of the PlotMarker list is being superimposed on every point in the plot. Here is the code which returns similarly undesired behavior. Instead of letters, I'm using points. Nonetheless, the problem is the same. The desired behavior is for the points to scale to the values of HourlyDataPointCount. --------8<-------- HourlyAverageCost = {186.8235294117647, 153.28722772277229, 148.25412844036697, 147.67576719576721, 148.1043396226415, 147.34375, 142.72424242424245, 141.44635627530366, 152.81413333333333, 151.30989583333334, 153.04958677685951, 153.12459893048128, 163.7921212121212, 184.74429223744292, 177.25316455696202, 140.55072463768116, 215.27272727272728, 149.90322580645162, 138.625, 94.0, 0, 140.0625, 142.44230769230768}; HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; Points = Map[ Graphics[{PointSize[Log[#/10 + 0.001]], Point[{0, 0}]}] &, HourlyDataPointCount] DateListPlot[Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, Frame -> False, PlotRange -> {Automatic, {0, 350}}, PlotMarkers -> Points] -------->8-------- Thanks in advance, Dan
From: Dan Loewenherz on 7 Jun 2010 08:07 Bob, Your solution worked great! Thank you so much. -Dan On Sun, Jun 6, 2010 at 6:56 AM, Bob Hanlon <hanlonr(a)cox.net> wrote: > > If you want each point to have its own style then each point must be a > separate list, i.e., Map List onto the data. > > HourlyAverageCost = { > 186.8, 153.3, 148.3, 147.7, 148.1, > 147.3, 142.7, 141.4, 152.8, 151.3, > 153.0, 153.1, 163.8, 184.7, 177.3, > 140.6, 215.3, 149.9, 138.6, 94.0, > 0, 140.1, 142.4}; > > HourlyDataPointCount = { > 17, 101, 109, 189, 159, > 160, 231, 494, 375, 384, > 242, 187, 165, 219, 158, > 69, 11, 31, 8, 1, > 0, 16, 52}; > > Hours = Map[ > DateString[{2010, 1, 1, #, 0, 0}] &, > Array[# &, 23]]; > > Points = Map[Graphics[ > {AbsolutePointSize[#/18 + 1], > Point[{0, 0}]}] &, > HourlyDataPointCount]; > > DateListPlot[ > List /@ Transpose[{Hours, HourlyAverageCost}], > ImageSize -> 600, > LabelStyle -> Directive[ > FontFamily -> "Helvetica", "Medium"], > DateTicksFormat -> {"HourShort", " ", "AMPM"}, > PlotStyle -> Black, > Frame -> False, > PlotRange -> {Automatic, {0, 350}}, > PlotMarkers -> Points] > > Or just using PlotStyle rather than PlotMarkers > > DateListPlot[ > List /@ Transpose[{Hours, HourlyAverageCost}], > ImageSize -> 600, > LabelStyle -> Directive[ > FontFamily -> "Helvetica", "Medium"], > DateTicksFormat -> {"HourShort", " ", "AMPM"}, > PlotStyle -> (Directive[Black, > AbsolutePointSize[#]] & /@ (28*Rescale[HourlyDataPointCount] + 1)), > Frame -> False, > PlotRange -> {Automatic, {0, 350}}] > > > Bob Hanlon > > ---- Dan Loewenherz <dloewenherz(a)gmail.com> wrote: > > ============= > Hi all, > > I'm trying to use some Graphics elements as markers for data points in > my DateListPlot. I'm running into an issue where the first element of > the PlotMarker list is being superimposed on every point in the plot. > Here is the code which returns > similarly undesired behavior. Instead of letters, I'm using points. > Nonetheless, the problem is the same. > > The desired behavior is for the points to scale to the values of > HourlyDataPointCount. > > --------8<-------- > > HourlyAverageCost = {186.8235294117647, 153.28722772277229, > 148.25412844036697, 147.67576719576721, 148.1043396226415, > 147.34375, 142.72424242424245, 141.44635627530366, > 152.81413333333333, 151.30989583333334, 153.04958677685951, > 153.12459893048128, 163.7921212121212, 184.74429223744292, > 177.25316455696202, 140.55072463768116, 215.27272727272728, > 149.90322580645162, 138.625, 94.0, 0, 140.0625, > 142.44230769230768}; > > HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, > 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; > > Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; > > Points = Map[ > Graphics[{PointSize[Log[#/10 + 0.001]], Point[{0, 0}]}] &, > HourlyDataPointCount] > > DateListPlot[Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, > LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], > DateTicksFormat -> {"HourShort", " ", "AMPM"}, > PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, > Frame -> False, PlotRange -> {Automatic, {0, 350}}, > PlotMarkers -> Points] > > -------->8-------- > > Thanks in advance, > Dan > > >
From: David Park on 7 Jun 2010 08:07 The problem is that a single PlotMarker is being used for each data set and you are plotting only one basic data set. The solution is to add the disks as extra items in the plot. Although this can probably be done with regular Mathematica, perhaps using Prolog, I find it easiest to use the Presentations package that is designed in part to more easily make custom graphics. Needs["Presentations`Master`"] HourlyAverageCost = {186.8235294117647, 153.28722772277229, 148.25412844036697, 147.67576719576721, 148.1043396226415, 147.34375, 142.72424242424245, 141.44635627530366, 152.81413333333333, 151.30989583333334, 153.04958677685951, 153.12459893048128, 163.7921212121212, 184.74429223744292, 177.25316455696202, 140.55072463768116, 215.27272727272728, 149.90322580645162, 138.625, 94.0, 0, 140.0625, 142.44230769230768}; HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; point[i_] := Module[ {t = AbsoluteTime[{2010, 1, 1, i, 0}], y = Part[HourlyAverageCost, i], count = Part[HourlyDataPointCount, i], maxcount = Max[HourlyDataPointCount], radius}, radius = 20.0 Sqrt[count/maxcount]; Tooltip[{AbsoluteThickness[1], If[radius > 1, CirclePoint[{t, y}, radius, Black, Orange], CirclePoint[{t, y}, 4, Black, White]], Black, AbsolutePointSize[3], Point[{t, y}]}, count] ] dateticks = CustomDateTicks[{DateString[{2010, 1, 1, 0, 0}], DateString[{2010, 1, 1, 23, 0}], {3, "Hour"}, 3}, DateString[#, {"Hour12Short", " ", "AMPM"}] &]; Draw2D[ {Table[point[i], {i, 1, 23}], AbsoluteThickness[1], DateListDraw[Transpose[{Hours, HourlyAverageCost}], Joined -> True, PlotRange -> All] }, AspectRatio -> .3, PlotRange -> {-10, 250}, Frame -> True, FrameLabel -> {"Time of Day", "Average Cost"}, FrameTicks -> {{Automatic, Automatic}, {dateticks, dateticks // NoTickLabels}}, PlotLabel -> "Example of a Weighted DateListPlot", ImageSize -> 400] Peter Lindsay at the School of Mathematics and Statistics at the University of St Andrews [ http://www.mcs.st-and.ac.uk/ ] kindly helps me keep an archive of Presentation solutions to MathGroup questions. These are available in both notebook and PDF form at: http://blackbook.mcs.st-and.ac.uk/~Peter/djmpark/html/ This should appear there within a day or two as Weighted DateListPlot. David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Dan Loewenherz [mailto:dloewenherz(a)gmail.com] Hi all, I'm trying to use some Graphics elements as markers for data points in my DateListPlot. I'm running into an issue where the first element of the PlotMarker list is being superimposed on every point in the plot. Here is the code which returns similarly undesired behavior. Instead of letters, I'm using points. Nonetheless, the problem is the same. The desired behavior is for the points to scale to the values of HourlyDataPointCount. --------8<-------- HourlyAverageCost = {186.8235294117647, 153.28722772277229, 148.25412844036697, 147.67576719576721, 148.1043396226415, 147.34375, 142.72424242424245, 141.44635627530366, 152.81413333333333, 151.30989583333334, 153.04958677685951, 153.12459893048128, 163.7921212121212, 184.74429223744292, 177.25316455696202, 140.55072463768116, 215.27272727272728, 149.90322580645162, 138.625, 94.0, 0, 140.0625, 142.44230769230768}; HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; Points = Map[ Graphics[{PointSize[Log[#/10 + 0.001]], Point[{0, 0}]}] &, HourlyDataPointCount] DateListPlot[Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, Frame -> False, PlotRange -> {Automatic, {0, 350}}, PlotMarkers -> Points] -------->8-------- Thanks in advance, Dan
From: Chris Degnen on 7 Jun 2010 08:07
Dan Loewenherz asked: > Hi all, > > I'm trying to use some Graphics elements as markers for data points in > my DateListPlot. I'm running into an issue where the first element of > the PlotMarker list is being superimposed on every point in the plot. > Here is the code which returns > similarly undesired behavior. Instead of letters, I'm using points. > Nonetheless, the problem is the same. > > The desired behavior is for the points to scale to the values of > HourlyDataPointCount. > > --------8<-------- > > HourlyAverageCost = {186.8235294117647, 153.28722772277229, > 148.25412844036697, 147.67576719576721, 148.1043396226415, > 147.34375, 142.72424242424245, 141.44635627530366, > 152.81413333333333, 151.30989583333334, 153.04958677685951, > 153.12459893048128, 163.7921212121212, 184.74429223744292, > 177.25316455696202, 140.55072463768116, 215.27272727272728, > 149.90322580645162, 138.625, 94.0, 0, 140.0625, > 142.44230769230768}; > > HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, > 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; > > Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; > > Points = Map[ > Graphics[{PointSize[Log[#/10 + 0.001]], Point[{0, 0}]}] &, > HourlyDataPointCount] > > DateListPlot[Transpose[{Hours, HourlyAverageCost}], ImageSize -> 600, > LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], > DateTicksFormat -> {"HourShort", " ", "AMPM"}, > PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, > Frame -> False, PlotRange -> {Automatic, {0, 350}}, > PlotMarkers -> Points] > > -------->8-------- > > Thanks in advance, > Dan > How's this? HourlyAverageCost = {186.8235294117647, 153.28722772277229, 148.25412844036697, 147.67576719576721, 148.1043396226415, 147.34375, 142.72424242424245, 141.44635627530366, 152.81413333333333, 151.30989583333334, 153.04958677685951, 153.12459893048128, 163.7921212121212, 184.74429223744292, 177.25316455696202, 140.55072463768116, 215.27272727272728, 149.90322580645162, 138.625, 94.0, 0, 140.0625, 142.44230769230768}; HourlyDataPointCount = {17, 101, 109, 189, 159, 160, 231, 494, 375, 384, 242, 187, 165, 219, 158, 69, 11, 31, 8, 1, 0, 16, 52}; Hours = Map[DateString[{2010, 1, 1, #, 0, 0}] &, Array[# &, 23]]; (*Changed PointSize[Log[#/10+0.001]] to PointSize[#/1000] for convenience*) Points = Map[Graphics[{PointSize[#/1000], Point[{0, 0}]}] &, HourlyDataPointCount]; (*Partitioned the dataset so each set takes a different point and add again \ for the line*) DateListPlot[ Append[Partition[Transpose[{Hours, HourlyAverageCost}], 1], Transpose[{Hours, HourlyAverageCost}]], ImageSize -> 600, LabelStyle -> Directive[FontFamily -> "Helvetica", "Medium"], DateTicksFormat -> {"HourShort", " ", "AMPM"}, PlotStyle -> {{Thick, RGBColor[0, 0, 0]}}, Joined -> True, Frame -> False, PlotRange -> {Automatic, {0, 350}}, PlotMarkers -> Points] |