Message Boards Message Boards

0
|
1102 Views
|
5 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Inconsistent tickmarks on 2D plots

Posted 5 months ago

This is an extended version of a recent post (one in which I neglected to add editable code: apologies). I have found that Mathmatica sometimes adds minor tickmarks and sometimes doesn't. (I'm calling major tickmarks those placed at ticks – either those that are automatically generated or those specified with the Ticks option – and minor tickmarks those that are regularly spaced between major ticks.) Here are two versions of almost identical code (varying primarily in the plotting range, range of gridlines and the number of specified ticks):

Version1: major and minor tickmarks appear

Plot[2 Sin[x], {x, -3, 3},
PlotStyle -> Red,
AxesLabel -> {x, y},
PlotRange -> {-3, 3},
LabelStyle -> 
Directive[Black, 14, Italic, FontFamily -> "Times New Roman"],
GridLines -> {Range[-3, 3, 1], Range[-3, 3, 1]},
Ticks -> {-2, -1, 1, 2},
TicksStyle -> Directive[Black, Plain, 12],
AxesStyle -> Arrowheads[{Automatic, Automatic}],
AspectRatio -> 1
]

Version2: major and tickmarks only; no minor tickmarks

Plot[2 Sin[x], {x, -10, 10},
 PlotStyle -> Red,
 AxesLabel -> {x, y},
 PlotRange -> {-11, 11},
 LabelStyle -> 
  Directive[Black, 14, Italic, FontFamily -> "Times New Roman"],
 GridLines -> {Range[-10, 10, 1], Range[-10, 10, 1]},
 Ticks -> {{-10, -5, 5, 10}, {-10, -5, 5, 10}},
 TicksStyle -> Directive[Black, Plain, 12],
 AxesStyle -> Arrowheads[{Automatic, Automatic}],
 AspectRatio -> 1
 ]

Can anyone explain this inconsistency or suggest a workaround so that I can get minor tickmarks to appear as well as the major ones? TIA.

Geoffrey

POSTED BY: Geoffrey Marnell
5 Replies

The answer is simple. In the first case you committed error in tick definition. You give ticks only for one axis. The ticks were changed to Automatic by Mathematica. You can write any numbers, for example Ticks->{-3,-2,2,5}. The ticks will be same as previously. You must define ticks for two axes as in the second case. I suppose that minor ticks are plotted only for Automatic case.

POSTED BY: Ivan Siahlo

Thank you Ivan. Yes, I think you are right. Minor tickmarks only seem to be added if the Ticksoption is set to Automatic.

POSTED BY: Geoffrey Marnell

Thanks Gianluca , but extending the plotting range didn't fix the problem. It did expose the explicitly specified ticks (10) near the end of the x and y axes, but that was not the issue I raised. My issue was with the absence of tickmarks on the axes (i.e. the short lines that mark out the gradations or intervals along the axes). The minor tickmarks (i.e. those between the ticks explicitly specified with the Ticks rule) are present in the first version, but not the second – and yet the versions are nearly identical.

POSTED BY: Geoffrey Marnell

I suppose Mathematica has an algorithm that chooses reasonable tickmarks for each specific situation, on aesthetic grounds. Among the criteria, there is probably one against too many labels close together. If you need them, you mustk ask for them explicitly.

POSTED BY: Gianluca Gorni

Give more horizontal space for the ticks, for example with PlotRange -> {{-11, 12}, {-11, 11}}

POSTED BY: Gianluca Gorni
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