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

标签 wolfram-mathematica plot

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

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

最佳答案

Howard 已经在你想要标签的情况下给出了正确的答案 Pi , 2 Pi等要在值 Pi , 2 Pi等等。

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

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

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

enter image description here

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

enter image description here

关于wolfram-mathematica - 如何选择mathematica中绘图轴上显示的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7132794/

相关文章:

plot - 从数据文件读取的 gnuplot 标签中的上标/下标

python - 使用默认颜色图绘制数据帧的列,但一列使用不同的颜色

c# - OxyPlot 在 PlotView/PlotModel 中被点击位置

r - 我可以在 facet 包裹的 ggplot 中设置动态轴限制吗?

wolfram-mathematica - 如何在带有多个定位器的 LocatorPane 中使用 AutoAction->True?

python - 当 Mathematica 轻松成功时,SymPy 的零空间陷入困境

wolfram-mathematica - 提高(或替代)RegionPlot 的速度

r - R中的堆积柱状图

pdf - 优化 Mathematica 生成的 eps/pdf 文件的大小

matlab - 通过自动引入时间变量或以任何其他方式简化非常长的符号表达式