如何选择mathematica中绘图轴上显示的数字?

发布于 2024-11-30 11:29:55 字数 113 浏览 3 评论 0原文

我已经检查了 Mathematica 文档中心中的所有示例和设置,但找不到任何有关如何选择将在轴上显示的数字的示例。

如何将绘图轴编号(如 2,4,6,..)更改为 PI,2PI,3PI,...?

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,...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缱倦旧时光 2024-12-07 11:29:55

如果您希望标签 Pi2 Pi 等处于值<,Howard 已经给出了正确答案/em> Pi2 Pi 等。

有时您可能希望在特定值处使用替代刻度标签,而不重新缩放数据。

文档中的其他示例之一显示了如何:

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

在此处输入图像描述

我有一套用于格式化的小型自定义函数 < code>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]]}]]

并设置:

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

示例:

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]}]

在此处输入图像描述

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, "\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 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

星星的轨迹 2024-12-07 11:29:55

您可以在此处找到示例:

Ticks -> {{Pi, 2 Pi, 3 Pi}, {-1, 0, 1}}

You can find an example here:

Ticks -> {{Pi, 2 Pi, 3 Pi}, {-1, 0, 1}}
ヅ她的身影、若隐若现 2024-12-07 11:29:55

Ticks 还接受一个函数,这将省去您手动列出点或每次更改最大值的麻烦。下面是一个示例:

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]

在此处输入图像描述

如果您希望更灵活地自定义刻度,您可能需要查看 LevelScheme

Ticks also accepts a function, which will save you the trouble of listing the points manually or having to change the max value each time. Here's 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 want more flexibility in customizing your ticks, you might want to look into LevelScheme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文