Message Boards Message Boards

1
|
6193 Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Why does ListPlot change when option is given explicitly?

Hello,

I am trying to understand the unexpected result of this simple code (using version 11.0.0.0 student edition):

a = ListPlot[Table[{x, x}, {x, 1, 5, 0.01}]]
AbsoluteOptions[a, PlotRange]
AbsoluteOptions[a, PlotRangePadding]
b = ListPlot[Table[{x, x}, {x, 1, 5, 0.01}], %[[1]]]
AbsoluteOptions[b, PlotRange]
AbsoluteOptions[b, PlotRangePadding]

Basically, plot b is the same as plot a, except I explicitly enter the default option used in plot a for plot range padding.

The result is that the plot range changes. For plot a the plot range was (1,5) for x and (0,5) for y, and for plot b the plot range is (1,5) for both axes. See attached file.

The value for plot range padding does not change (scaled 0.02, 0.02, 0.02, and 0.05).

The actual graphs printed are also different. In a the y axis starts at zero, so there is a band with no data (y from zero to one). For b the y axis starts at 1, and the x axis gets cut off in the printed result (this almost qualifies as a bug for me).

Ultimately what I am trying to do is to get the ListPlot to include all the points in the plot range (PlotRange -> All or Full), but to not add extra space differently for the x and y axes. I don't mind some padding, just don't like the difference in x and y. Basically, when I plot the same list on x and y, I want to see it go in a corner-to-corner direction, similar to the result of Plot[x,{x,1,5}].

Thanks in advance,

Otto Linsuaín

Attachments:
POSTED BY: Otto Linsuain
6 Replies

Hello Henrik,

Thanks for your reply. Sorry I did not read it earlier, sort of got disconnected from this post. I just opened this post because I saw the same thing you display for version 9, it works fine! (mine is in Linux). So, something got broken between 9 and 11. If I remember right (don't have it in front of me) in version 11 in the second graph the x-axis is at y=1, but does not show in the graph at all.

It is very interesting that version 9 gets it right. There must be a flag one can reset to what it used to be. I may give it a try when I get home, I may open them side by side (I have access to different versions from different computers) and see if the options show any difference.

Best,

Otto.

POSTED BY: Otto Linsuain

Hi Otto,

I can confirm the effect you are describing (my system: 11.0.1 for Linux x86 (64-bit) (September 21, 2016)) and I find this a "strange behavior" indeed. As result of AbsoluteOptions I would expect some absolute value, not some scaled - the documentation seems to indicate the same! Interestingly this appears to be different (i.e. OK) in older versions, e.g.:

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner

The most common reason in programming: not known in advance!

I suppose I could code something like PlotRange-> {Min[data],Max[data]} (I have done it that before) and PlotRangePadding-> some small number (never dealt with it). And then perhaps also ensure I get nice round numbers for the ticks. It almost feels like I am working around a deficiency.

This all came about from me noticing that Plot[x,{x,1,5}] draws a line from corner to corner, but ListPlot[Table[{x,x},{x,1,5,0.01}]] does not. They use different defaults for deciding the ranges. It is a bit annoying for what I am doing, even if it is not the end of the world.

I suppose it is not that big a deal, because for any individual graph one can always fix it by hand, as you point out. It is just a nuisance that the default behavior treats x and y differently. Add to that the fact that entering the same value of the option changes the result (and even cuts off one axis), and one can almost call it a bug.

Thanks,

Otto.

POSTED BY: Otto Linsuain

Hello Sander,

Thanks for replying to my post. I think I mean to use the PlotRangePadding option (one percent sign).

If I set plot b to be the same as a, but implicitly entering the PlotRange option that a used, then I think nothing happens, and plot b will look the same as plot a as it should be (although strangely enough, in that case the value for PlotRangePadding changes).

But my point remains as originally stated. If I use in plot b the value of PlotRangePadding that a used, then the plot changes. Apparently, entering an implicit value for one of these options changes the other. In either case I do not get the result I wanted, which is to use the same padding in y as used in x.

Thanks,

Otto LinsuaĆ­n

POSTED BY: Otto Linsuain

But why don't you set it yourself to the same value? Either in Scaled or none-scaled units?

POSTED BY: Sander Huisman

You need the answer before that:

a = ListPlot[Table[{x, x}, {x, 1, 5, 0.01}]]
AbsoluteOptions[a, PlotRange]
AbsoluteOptions[a, PlotRangePadding]
b = ListPlot[Table[{x, x}, {x, 1, 5, 0.01}], %%[[1]]] (* notice the double percent here *)
AbsoluteOptions[b, PlotRange]
AbsoluteOptions[b, PlotRangePadding]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract