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: [mg117615] Re: Problem with DateListPlot Aspect Ratio
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 24 Mar 2011 06:31:12 -0500 (EST)

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: [mg117615] 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 Iwrote 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: Problem with DateListPlot Aspect Ratio
  • 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: Re: Problem with DateListPlot Aspect Ratio