Wolfram mathematica 在Mathematica绘图中强制x轴与y轴对齐

Wolfram mathematica 在Mathematica绘图中强制x轴与y轴对齐,wolfram-mathematica,plot,Wolfram Mathematica,Plot,在Mathematica中,当我绘制东西时,有时我并不总是让x轴与绘图的确切底部对齐。我有没有办法强迫它一直这样做 下面是我所说的一个例子: 我希望X轴与底部的零刻度标记线完全对齐,而不是在Y轴的中间,因为它在该图像中。 有什么办法可以做到这一点吗?使用选项您也可以使用类似于:Frame->{{Automatic,None},{Automatic,None}} (我还认为,默认情况下,它没有选择{0,0},这意味着y=0被PlotRangePadding带入范围。因此,这可能是另一个需要注意的选

在Mathematica中,当我绘制东西时,有时我并不总是让x轴与绘图的确切底部对齐。我有没有办法强迫它一直这样做

下面是我所说的一个例子:

我希望X轴与底部的零刻度标记线完全对齐,而不是在Y轴的中间,因为它在该图像中。


有什么办法可以做到这一点吗?

使用选项

您也可以使用类似于:
Frame->{{Automatic,None},{Automatic,None}}


(我还认为,默认情况下,它没有选择
{0,0}
,这意味着
y=0
PlotRangePadding
带入范围。因此,这可能是另一个需要注意的选项。)

以下内容将在左侧和底部绘制轴,而不考虑坐标值:

aPlot[f_, var_, opts : OptionsPattern[]] :=
 Plot[f, var,
  AxesOrigin -> 
   First /@ (# /. AbsoluteOptions[Plot[f, var, opts], #] &@PlotRange), opts]

aPlot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, Filling -> Axis]

以下是(IMO)基于belisarius代码的更优雅的方法,该代码使用了
DisplayFunction
选项(请参见关于该选项的有趣讨论):

这两种方法的唯一缺点是。解决方案是使用(这将提供完整的
PlotRange
,并添加显式值
PlotRangePadding
):

值得注意的是,这段代码给出的渲染与简单地指定
帧->{{Automatic,None},{Automatic,None}},Axes->False的渲染完全相同:

pl1 = Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
   Filling -> Axis, 
   DisplayFunction -> 
    Function[{plot}, 
     Show[plot, AxesOrigin -> First /@ completePlotRange[plot], 
      DisplayFunction -> Identity]]];
pl2 = Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
   Filling -> Axis, Frame -> {{Automatic, None}, {Automatic, None}}, 
   Axes -> False];
Rasterize[pl1] == Rasterize[pl1]

=> True

我想如果你能将产生该绘图/图像的mathematica语句添加到你的问题中会有所帮助吗?我知道PlotRange异常,但我认为它与某些plot[]表兄妹有关,但与plot[]本身无关。@belisarius:我喜欢你的解和Alexey Popkov的导出解的普遍性,但是我想远离它们,因为它要复杂得多,而且我需要做的对齐很容易通过
AxesOrigin->{0,0}
得到满足。太糟糕了,Mathematica中还没有这样的东西。@Mike如果你只需要{0,0}这个例子,显然
AxesOrigin
是一个不错的选择!
Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
 Filling -> Axis, 
 DisplayFunction -> 
  Function[{plot}, 
   Show[plot, 
    AxesOrigin -> 
     First /@ (PlotRange /. AbsoluteOptions[plot, PlotRange]), 
    DisplayFunction -> Identity]]]
completePlotRange[plot_] := 
 Last@Last@
   Reap[Rasterize[
     Show[plot, Ticks -> (Sow[{##}] &), DisplayFunction -> Identity], 
     ImageResolution -> 1]]
Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
 Filling -> Axis, 
 DisplayFunction -> 
  Function[{plot}, 
   Show[plot, AxesOrigin -> First /@ completePlotRange[plot], 
    DisplayFunction -> Identity]]]
pl1 = Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
   Filling -> Axis, 
   DisplayFunction -> 
    Function[{plot}, 
     Show[plot, AxesOrigin -> First /@ completePlotRange[plot], 
      DisplayFunction -> Identity]]];
pl2 = Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, 
   Filling -> Axis, Frame -> {{Automatic, None}, {Automatic, None}}, 
   Axes -> False];
Rasterize[pl1] == Rasterize[pl1]

=> True