Mathematica: ListPlot weirdness

  • Context: Mathematica 
  • Thread starter Thread starter Rasalhague
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while using Mathematica's ListPlot function to visualize a set of points. Participants explore problems related to point visibility, axis scaling, and tick labeling in the plot, focusing on both theoretical and practical aspects of the software's functionality.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes an issue where not all intended points are displayed in the plot, questioning why only some points appear and why the aspect ratio does not yield equally scaled axes.
  • Another participant suggests that the missing points may still be present but not clearly visible, recommending a smaller point size to expose them.
  • A different participant reports that their experience differs, as all points are plotted correctly on their end, and they mention that using Automatic for aspect ratio is preferable for consistent scaling.
  • One participant notes that changing the aspect ratio to Automatic produces all points but raises a question about how to adjust the axes to cross at the origin (0,0) and how to set specific tick marks numerically.
  • Another participant provides links to Mathematica documentation for specifying axes origin and tick marks, indicating these features can resolve some of the issues raised.
  • A participant expresses gratitude for the solutions provided but questions why their alternative method for setting ticks does not work as expected, leading to confusion about tick intervals and labels.
  • One participant identifies a mistake in specifying the Ticks option multiple times, which led to unexpected behavior in the plot output.
  • Another participant reflects on the behavior of Mathematica when handling multiple options, noting that it consistently uses the first defined option, which they found surprising.

Areas of Agreement / Disagreement

Participants express differing experiences with the ListPlot function, with some agreeing on the need for adjustments to achieve desired outcomes while others report successful results without the same modifications. The discussion remains unresolved regarding the underlying reasons for the discrepancies in plotting behavior.

Contextual Notes

Some participants mention specific configurations and options that may influence the output, but there is no consensus on the best approach to achieve the desired plot characteristics. Limitations in understanding the software's behavior and the implications of option precedence are noted.

Rasalhague
Messages
1,383
Reaction score
2
In Mathematica 7, I entered

Code:
u = {1, 2, 3, 5, 7, 8, 10, 11}; v = {1, 2, 4, 5, 4, 3, 1, 1}; w = 
 Transpose[{u, v}]; ListPlot[w, PlotRange -> All, 
 AspectRatio -> 1/1]

I wanted this to display a dot at each of the 8 points of w,

{{1, 1}, {2, 2}, {3, 4}, {5, 5}, {7, 4}, {8, 3}, {10, 1}, {11, 1}},

and to show them on a diagram whose axes have the same scale. Instead, it displays a dot at these 4 points only

{{2, 4}, {5, 5}, {7, 4}, {8, 3}},

and the gaps between integers are much smaller on the horizontal axis. Replacing 1/1 with Automatic produces axes of a similar scale, but they look untidy because only every other integer is labelled on the horizonal axis, whereas every integer is labelled on the vertical axis. Replacing All with Full makes no visible difference.

The axes are at least long enough to accomadate all of the correct points: the vertical one goes up to 5, the horizontal to 11.

Why doesn't it plot the right points? Why does it not plot the full amount of points? Why doesn't 1/1 give equally scaled axes? How can I plot all of the right points on equally scalled axes with all integers labelled on both axes?
 
Physics news on Phys.org
I believe your points are actually there, they just aren't obvious.

This should expose them

u = {1, 2, 3, 5, 7, 8, 10, 11}; v = {1, 2, 4, 5, 4, 3, 1, 1}; w = Transpose[{u, v}]; ListPlot[w, PlotRange -> All, AspectRatio -> 1/1, PlotStyle -> PointSize[0.05]]
 
I don't get the behavior you get. For me it plots all of the points.

As you say, if you want the scale to be the same you need to use Automatic instead of 1.

If you want to force some specific tick marking you can e.g. define:
ticks[min_, max_] := Range[Ceiling[min], Floor[max]]
and then use the option
Ticks->ticks
 
How strange.

Code:
ListPlot[w, PlotRange -> All, AspectRatio -> Automatic, 
 PlotStyle -> PointSize[0.05]]

This produces a full set 8 big dots. It looks as if the axes actually cross at (2,1), in which case the dots are in the right places after all. How can I get the axes to cross in the standard place, at (0,0)? And is the a way to specify the scales numerically?

Code:
ticks[min_, max_] := Range[Ceiling[min], Floor[max]]; ListPlot[w, 
 PlotRange -> All, AspectRatio -> Automatic, 
 PlotStyle -> PointSize[0.025], Ticks -> ticks]

This labels all integers along the horizontal and vertical axes except at the quirky origin, (2,1).
 
Last edited:
Thanks! So, that's got the axes to cross at (0,0), or wherever I might want, and now I know how to force the dots to be the same size and all visible. DaleSpam's suggestion worked for the ticks, but I wonder why this alternative doesn't:

Code:
u = {1, 2, 3, 5, 7, 8, 10, 11}; v = {1, 2, 4, 5, 4, 3, 1, 1}; w = 
 Transpose[{u, v}]; hori = 
 Transpose[{Table[i, {i, 11}], Table[i, {i, 11}]}]; vert = 
 Transpose[{Table[i, {i, 5}], Table[i, {i, 5}]}]; ListPlot[w, 
 PlotStyle -> PointSize[0.01], Ticks -> Automatic, 
 AxesOrigin -> {0, 0}, Ticks -> {hori, vert}]

Shouldn't that put ticks at every unit from 1 to 11 on the horizontal axis, and label them in the natural way: 1, 2, 3,... ,11? (Instead, it puts ticks at intervals of 0.5, and labels them 1, 2, 3, etc. on the vertical, but 2, 4, 6, etc. on the horizontal.

{{x1,label1},{x2,label2},...} tick marks drawn with the specified labels
 
Rasalhague said:
Thanks! So, that's got the axes to cross at (0,0), or wherever I might want, and now I know how to force the dots to be the same size and all visible. DaleSpam's suggestion worked for the ticks, but I wonder why this alternative doesn't:

Code:
u = {1, 2, 3, 5, 7, 8, 10, 11}; v = {1, 2, 4, 5, 4, 3, 1, 1}; w = 
 Transpose[{u, v}]; hori = 
 Transpose[{Table[i, {i, 11}], Table[i, {i, 11}]}]; vert = 
 Transpose[{Table[i, {i, 5}], Table[i, {i, 5}]}]; ListPlot[w, 
 PlotStyle -> PointSize[0.01], [B]Ticks -> Automatic[/B], 
 AxesOrigin -> {0, 0}, [B]Ticks -> {hori, vert}[/B]]

Shouldn't that put ticks at every unit from 1 to 11 on the horizontal axis, and label them in the natural way: 1, 2, 3,... ,11? (Instead, it puts ticks at intervals of 0.5, and labels them 1, 2, 3, etc. on the vertical, but 2, 4, 6, etc. on the horizontal.
You have specified the same option twice. It looks like it just took the first one instead of the second one.
 
D'oh! Thanks, DaleSpam. Yeah, that was the trouble. This produces the diagram I wanted:

Code:
u = {1, 2, 3, 5, 7, 8, 10, 11}; v = {1, 2, 4, 5, 4, 3, 1, 1}; w = 
 Transpose[{u, v}]; hori = 
 Transpose[{Table[i, {i, 11}], Table[i, {i, 11}]}]; vert = 
 Transpose[{Table[i, {i, 5}], Table[i, {i, 5}]}]; ListPlot[w, 
 PlotStyle -> PointSize[0.01], AxesOrigin -> {0, 0}, 
 Ticks -> {hori, vert}, AspectRatio -> Automatic]
 
No worries. Actually, I learned something new from the mistake. It seemed strange to me that it silently used the first option. I had never observed that behavior, and I would have expected it to either throw an error or to use the last value. But it seems very consistent; if you have a sequence of options in which one option is defined multiple times it always seems to use the first one. I think it has to do with the behavior of the built-in function OptionValue which is used in programming functions with options.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
10
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 18 ·
Replies
18
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K