How to choose the numbers shown on the plot axes in math?

I already checked all the examples and settings in the Mathematica documentation center, but could not find any example of how to choose the numbers that will be displayed on the axes.

How to change the axis numbering of a graph, for example, 2,4,6, .. to PI, 2PI, 3PI, ...?

+3
source share
3 answers

Here you can find an example here:

Ticks -> {{Pi, 2 Pi, 3 Pi}, {-1, 0, 1}} 
+4
source

Howard has already given the correct answer if the labels are Pi , 2 Pi , etc. are in the values ​​of Pi , 2 Pi , etc.

Sometimes you may need to use placeholder tags with specific values ​​without rescaling the 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 set of small custom functions for formatting Ticks as I want them. This is probably too much information if you are just starting out, but you should know that you can use any number format and, if you want, replace anything with your ticks.

 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, "\n"] > 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 installation:

 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

+8
source

Ticks also accepts a feature that eliminates the need to list points manually or change the maximum value each time. Here is an example:

 xTickFunc[min_, max_] := Table[{i, i, 0.02}, {i, Ceiling[min/Pi] Pi, Floor[max/Pi] Pi, Pi}] Plot[Sinc[x], {x, -5 Pi, 5 Pi}, Ticks -> {xTickFunc, Automatic}, PlotRange -> All] 

enter image description here

If you need more flexibility in customizing your ticks, you can take a look at LevelScheme .

+3
source

Source: https://habr.com/ru/post/906448/


All Articles