MathGroup Archive 2011

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

Search the Archive

Re: Problem with DateListPlot Aspect Ratio

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117658] Re: Problem with DateListPlot Aspect Ratio
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 29 Mar 2011 06:55:06 -0500 (EST)

Needs["Calendar`"]

pointsnum = 300;
percentage = 1;

data = Transpose[{DatePlus[{2011, 1, 1}, #] & /@ Range[pointsnum],
    RandomReal[100, pointsnum]}];

heightWidthRatio = RandomReal[{.1, .4}]

0.205389

Column[{Row[{
    "Portion of data",
    Spacer[5],
    Slider[Dynamic[percentage], ImageSize -> Large],
    Spacer[5],
    Dynamic[percentage]}],
  Framed[Dynamic[
    DateListPlot[data,
     Joined -> True,
     ImageSize -> Scaled[1],
     AspectRatio -> .8 heightWidthRatio,
     PlotRange -> {
       {data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]},
       {-2, 102}}]],
   ImageSize -> 800*{1, heightWidthRatio},
   FrameMargins -> {{0, 0}, {0, 0}}]}]


Bob Hanlon

---- "Miranda wrote:

==========================
Your idea works as long as the height for the graph does not matter, in my case the DateListPlot will be inside a Framed, the size of the frame will be dynamic too. I modify the code you sent me in order to illustrate my problem.

Needs["Calendar`"]

pointsnum = 300;
percentage = 1;

data = Transpose[{DatePlus[{2011, 1, 1}, #] & /@ Range[pointsnum],
    RandomReal[100, pointsnum]}];

{width, height} = {0.8780604201513872`, 0.12400644280815411`}

Column[{Row[{"Portion of data", Spacer[5],
    Slider[Dynamic[percentage], ImageSize -> Large], Spacer[5],
    Dynamic[percentage]}],
  Dynamic[DateListPlot[data, Joined -> True, ImageSize -> 800*width,
    AspectRatio -> height/width,
    PlotRange -> {{data[[1, 1]],
       DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {-2,
       102}}]],
  Framed[Dynamic[
    DateListPlot[data, Joined -> True, ImageSize -> 800*width,
     AspectRatio -> height/width,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {-2,
        102}}]], ImageSize -> 800*{width, height},
   FrameMargins -> {{0, 0}, {0, 0}}],
  Framed[Dynamic[
    DateListPlot[data, Joined -> True,
     ImageSize -> 800*{width, height}, AspectRatio -> Full,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {-2,
        102}}]], ImageSize -> 800*{width, height},
   FrameMargins -> {{0, 0}, {0, 0}}]}]

In the first row is the Slider that changes the Portion of data. In the second row is the DateListPlot you get with the code you sent me, the third row shows how it looks inside the Framed element, in the fourth row I'm illustrating the picture I need, I hardcoded the height and width of the image to {0.8780604201513872`, 0.12400644280815411`}, but it will be a Dynamic value and the contained DateListPlot should look as the one shown in the fourth row, where AspectRatio is defined as Full, as you can see the DateListPlot adjust exactly to the available space, but again, using a portion of datavalue behind about 0.7 the weird lines appear. For me is important that the Plot adjusts to the available space because I will have a grid of maybe dozens of them in order to be shown in the screen at the same time 


-----Original Message-----
From: Bob Hanlon [mailto:hanlonr at cox.net]
Sent: Wednesday, March 23, 2011 5:22 PM
To: Miranda, Juan; mathgroup at smc.vnet.net
Subject: [mg117658] RE: RE: [mg117581] Problem with DateListPlot Aspect Ratio

Here the height and width are random numbers. The aspect ratio adjusts accordingly.

Needs["Calendar`"]

pointsnum = 300;
percentage = 1;

data = Transpose[{
    DatePlus[{2011, 1, 1}, #] & /@ Range[pointsnum],
    RandomReal[100, pointsnum]}];

{width, height} = {RandomReal[{.6, 1}], RandomReal[{.1, .4}]}

{0.796679, 0.253861}

Column[{Row[{"Portion of data",
    Spacer[5],
    Slider[Dynamic[percentage],
     ImageSize -> Large],
    Spacer[5],
    Dynamic[percentage]}],
  Dynamic[DateListPlot[data,
    Joined -> True,
    ImageSize -> 800*width,
    AspectRatio -> height/width,
    PlotRange -> {
      {data[[1, 1]], DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]},
      {-2, 102}}]]}]


Bob Hanlon

---- "Miranda wrote:

==========================
Ok, I know that code works, but just for the case where the ImageSize of the DateListPlot is {800,200}, Actually the size for the image depends on the size of a pane then when the ImageSize of the pane is {200,800} the appearance of the DateListPlot will now take the whole space. I mean the height and width of the plot can take any value between let's say 100 and 800, I prepared a code in order to illustrate what I mean:

Needs["Calendar`"]
pointsnum = 300;
percentage = 1;
data = Transpose[{Map[(DatePlus[{2011, 1, 1}, #]) &,
     Range[pointsnum]], RandomReal[100, pointsnum]}];
width = 1;
height = 0.25;

Grid[{{Grid[{{"Range Percentage: ",
      Slider[Dynamic[percentage], {0.1, 1}],
      Dynamic[percentage]}, {"Width: ",
      Slider[Dynamic[width], {0.1, 1}], Dynamic[width]}, {"Height: ",
      Slider[Dynamic[height], {0.1, 1}],
      Dynamic[height]}}]}, {Dynamic[
    DateListPlot[data, Joined -> True,
     ImageSize -> 800*{width, height}, AspectRatio -> GoldenRatio,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {0,
        100}}, Background -> LightYellow]]}, {Dynamic[
    DateListPlot[data, Joined -> True,
     ImageSize -> 800*{width, height}, AspectRatio -> Full,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {0,
        100}}, Background -> LightYellow]]}, {Dynamic[
    DateListPlot[data, Joined -> True,
     ImageSize -> 800*{width, height}, AspectRatio -> 1/4,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {-2,
        102}}, Background -> LightYellow]]
   }}]

This example includes at the end the code you sent me, I know that specifying the aspect ratio makes the plot to be shown, but if the ImageSize of the whole DateListPlot changes, then the figure will not use the whole available space.

Best.

Juan



-----Original Message-----
From: Bob Hanlon [mailto:hanlonr at cox.net]
Sent: Wednesday, March 23, 2011 4:41 AM
To: Miranda, Juan; mathgroup at smc.vnet.net
Subject: [mg117658] Re: [mg117581] Problem with DateListPlot Aspect Ratio


Needs["Calendar`"]

pointsnum = 300;
percentage = 1;

data = Transpose[{
    DatePlus[{2011, 1, 1}, #] & /@ Range[pointsnum],
    RandomReal[100, pointsnum]}];

Column[{
  Row[{
    "Portion of data", Spacer[5],
    Slider[Dynamic[percentage], ImageSize -> Large], Spacer[5],
    Dynamic[percentage]}],
  Dynamic[
   DateListPlot[
    data,
    Joined -> True,
    ImageSize -> 800,
    AspectRatio -> 1/4,
    PlotRange ->
     {
      {data[[1, 1]],
       DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]},
      {-2, 102}}]]}]


Bob Hanlon

---- "Miranda wrote:

==========================
Hi everyone,

I have had some troubles with DateListPlot, my version of Mathematica is 8.0.1, so this is my problem.

I'm creating a random time indexed list with 300 data, in order to plot the data I'm using the DateListPlot function, I want to have the PlotRange varying with an slider in order to see a larger or smaller range of data. So I wrote the next problem to exemplify what is happening, I have an Slider that changes the percentage of time I want to see from 0 to 1, there are two DateListPlots, both of them plot the same 300 data points, and have the ImageSize defined as {800,200}, the first one as the AspectRatio defined as GoldenRatio, the second one has the AspectRatio defined as Full because I want the graphic to cover the whole imagesize space. So when percentage has the value of 1 (To show 100% the time range), both graphics work as expected.  But if I move the Slider in order to select a value of percentage behind 0.7 (approx. 70%), the first graph that is not the one that I want to implement works just fine, but the second one that is the one I want to implement just show som
 e!
 weird lines. I'm starting thinking that it is a bug. Can someone tell me how to correct this bug? I want to conserve the Time related ticks in the DateListPlot.

Needs["Calendar`"]
pointsnum = 300;
percentage = 1;
data = Transpose[{Map[(DatePlus[{2011, 1, 1}, #]) &,
     Range[pointsnum]], RandomReal[100, pointsnum]}];
Grid[{{Grid[{{Slider[Dynamic[percentage]], Dynamic[percentage]}}]}, {
   Dynamic[
    DateListPlot[data, Joined -> True, ImageSize -> {800, 200},
     AspectRatio -> GoldenRatio,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {0,
        100}}]]
   }, {
   Dynamic[
    DateListPlot[data, Joined -> True, ImageSize -> {800, 200},
     AspectRatio -> Full,
     PlotRange -> {{data[[1, 1]],
        DatePlus[data[[1, 1]], (pointsnum - 1)*percentage]}, {0,
        100}}]]
   }}]


Best.

Juan





  • Prev by Date: Re: StreamPlot or streamlines in 3D?
  • Next by Date: Re: Why Mathematica does not issue a warning when the calculations
  • Previous by thread: Re: Problem with DateListPlot Aspect Ratio
  • Next by thread: Mathematica debugger