Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

The problem came up in a plot of RGB data obtained by imaging the variable star d-Cephei with a DSLR camera on several successive nights. I tried to plot the R, G, B intensity points for each day in a column and place a bitmap of the star (taken that day) over the column. This worked fine with ListPlot during September, but with October coming up, it was clear I would need something like DateListPlot. But when I substituted DateListPlot, after rewriting the data structures appropriately, I found that the points would plot, but the bitmaps that I had inserted with Epilog disappeared. Furthermore, by adding a PlotRange statement, I could get the bitmaps, but the R, G, B intensity points would not display.

In what follows, I have tried to boil it down using just one suitable list of points for one color and just one bitmap created by rasterizing a Disk. Somewhat to my surprise, the problem is reproducible. As written, the image plotted with ListPlot shows it working properly, but it lacks the formatting of the date information on the x axis. The image plotted with DateListPlot formats the dates nicely, but it doesn't show the bitmap. My questions are:

  1. What will make the bitmap display with DateListPlot?
  2. How can I move the bitmap display above the range of the points on the Y axis, and below the title?
  3. Is it possible to specify a PlotRange in DateListPlot? How would one specify the range for the x axis?
  4. Why does this happen?
  5. When will a book be published listing all the do's and don't's of plots and graphics in Mathematica?

My code follows:

Clear[disk, datePts, pts, dateListPlot, listPlot]

disk = Rasterize[Graphics[Disk[]]];

datePts = {{{2012, 9, 24}, .1}, {{2012, 9, 25}, .35}, {{2012, 9, 
     26}, .75}, {{2012, 9, 27}, .90}, {{2012, 9, 28}, .60}, {{2012, 9,
      29}, .30}, {{2012, 9, 30}, .10}};

pts = {#[[1, 3]], #[[2]]} & /@ datePts;

ListPlot[
  pts,
  PlotStyle -> Directive[{Red, PointSize[Large]}],
  PlotLabel -> "ListPlot: Epilog disk visible",
  Epilog -> Inset[disk, {23.75, .8}, {0, 0}, .4],
  PlotRange -> {{23.5, 30.5}, {0, 1}},
  Background -> LightGray
  ]

DateListPlot[
 datePts,
 PlotStyle -> Directive[{Red, PointSize[Large]}],
 PlotLabel -> "DateListPlot: Epilog disk not visible",
 Epilog -> Inset[disk, {23.75, .8}, {0, 0}, .4],
 (* Activate PlotRange makes Epilog visible, but points will not be visible. *)
 (*PlotRange->{{23,30},{0,1}},*)
 Background -> LightGray
 ]
share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Re your question #1 (and #4): This is an interesting quirk related to the way dates are used as the x-coordinates in DateListPlot. To make the disk show, you need to use an x-coordinate that corresponds to the dates in the plot. In this case, a DateList like {2012,9,24} is what you need. Since you are also using the fourth argument to specify the size of the disk in terms of coordinates of the surrounding graphic, you need to bear in mind that in a DateListPlot, the x-coordinates are in seconds, i.e. each day is $24 \times 3600 = 86400$ seconds. In the example below, I have made the disk "three hours" wide.

So this works:

DateListPlot[datePts, PlotStyle -> Directive[{Red, PointSize[Large]}],
  PlotLabel -> "DateListPlot: Epilog disk is now visible", 
 Epilog -> Inset[disk, {{2012, 9, 24}, .8}, {0, 0}, 6*3600], 
 PlotRange -> {0, 1}, Background -> LightGray]

enter image description here

For PlotRange, the issue you had was that you were specifying the two-axis version. PlotRange->{0,1} just sets the plot range for the vertical axis. In answer to your question #3, to set the PlotRange for the horizontal axis as well, just use dates: PlotRange->{{{2012,9,24},{2012,10,3}},{0,1}}.

To answer question #2: you need to set PlotRangeClipping->False.

DateListPlot[datePts, PlotStyle -> Directive[{Red, PointSize[Large]}],
  PlotLabel -> "DateListPlot: Epilog disk is now visible", 
 Epilog -> Inset[disk, {{2012, 9, 27}, 1.01}, {0, 0}, 6*3600], 
 PlotRange -> {0, 1}, Background -> LightGray, PlotRangeClipping -> False]

enter image description here

As for question #5, I think there are a few people on this site that would be qualified to write it, but in the mean time you might want to have a look at Mathematica Navigator by Heikke Ruskeepaa or Michael Trott's Graphics Guidebooks.

share|improve this answer
    
More precisely: the abscissas in a DateListPlot[] are obtained by applying AbsoluteTime[] to the dates given... –  J. M. Oct 2 '12 at 3:48
    
Also an older (mid 90s?) book by Tom Wickham Jones. Haven't seen it for many years and may not be as relevant now post V5 but worth having a look if you can find it. –  Mike Honeychurch Oct 2 '12 at 3:48
    
Great answers to the questions. I'll look for the Trott and the Jones (@MikeHoneychurch). Ruskeepaa (3rd ed.) doesn't seem to go beyond the online documentation on this point. Thanks also @JM for the bit about AbsoluteTime. –  Gary Palmer Oct 2 '12 at 6:19
    
@Mike, you mean Mathematica Graphics? I think the ExtendGraphics` package can still be useful, if it can be updated... –  J. M. Oct 2 '12 at 8:05
    
@J.M. Yes. It is a very long time since I used the package and it was for field plots which are now built in, but the book itself was very good. –  Mike Honeychurch Oct 2 '12 at 9:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.