Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

wolfram mathematica - How to choose the numbers shown on the axes of a plot in mathemetica?

I have already checked all the examples and settings in the Mathematica documentation center, but couldn't find any example on how to choose the numbers that will be shown on the axes.

How do I change plot axis numbering like 2,4,6,.. to PI,2PI,3PI,...?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Howard has already given the correct answer in the case where you want the labels Pi, 2 Pi etc to be at the values Pi, 2 Pi etc.

Sometimes you might want to use substitute tick labels at particular values, without rescaling data.

One of the other examples in the documentation shows how:

Plot[Sin[x], {x, 0, 10}, 
 Ticks -> {{{Pi, 180 [Degree]}, {2 Pi, 360 [Degree]}, {3 Pi, 
  540 [Degree]}}, {-1, 1}}]

enter image description here

I have a suite of small custom functions for formatting Ticks the way I want them. This is probably too much information if you are just starting out, but it is worth knowing that you can use any number format and substitute anything into your ticks if desired.

myTickGrid[min_, max_, seg_, units_String, len_?NumericQ, 
  opts : OptionsPattern[]] := 
 With[{adj = OptionValue[UnitLabelShift], bls = OptionValue[BottomLabelShift]}, 
Table[{i, 
If[i == max, 
 DisplayForm[AdjustmentBox[Style[units, LineSpacing -> {0, 12}], 
   BoxBaselineShift ->  If[StringCount[units, "
"] > 0, adj + 2, adj]]], 
 If[i == min, 
  DisplayForm@AdjustmentBox[Switch[i, _Integer, 
     NumberForm[i, DigitBlock -> 3, 
      NumberSeparator -> "[ThinSpace]"], _, N[i]], 
    BoxBaselineShift -> bls], 
  Switch[i, _Integer, NumberForm[i, DigitBlock -> 3, 
    NumberSeparator -> "[ThinSpace]"], _, N[i]]]], {len, 0}}, {i,
 If[Head[seg] === List, Union[{min, max}, seg], Range[min, max, seg]]}]]

And setting:

Options[myTickGrid] = {UnitLabelShift -> 1.3, BottomLabelShift -> 0}
SetOptions[myTickGrid, UnitLabelShift -> 1.3, BottomLabelShift -> 0]

Example:

Plot[Erfc[x], {x, -2, 2}, Frame -> True, 
 FrameTicks -> {myTickGrid[-2, 2, 1, "x", 0.02, UnitLabelShift -> 0], 
   myTickGrid[0, 2, {0.25, .5, 1, 1.8}, "Erfc(x)", 0.02]}]

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...