2011-09-30 22 views
5

Mathematicaでは、時々プロットするときにプロットの正確なボトムとx軸が一致するとは限りません。私はいつもこれをやるように強制することができますか?Mathematicaプロットでx軸をy軸に合わせるようにする

ここで私が話しているかの例です:http://i.imgur.com/3lcWd.png

私はないとして、y軸の中央に、下部にゼロ目盛りの方法で完全に並ぶようにx軸を望みますそのイメージにあります。

私はこれを達成できますか?

+0

プロット/イメージを生成したmathematicaステートメントをあなたの質問に追加すると助けになると思いますか? – dbjohn

答えて

9

あなたはまた、のようなもの使用することができますオプションにAxesOrigin -> {0,0}

+0

パーフェクト!それはまさに私が探していたものです、ありがとう! –

4

を使用します。また、私はそれがデフォルトで{0,0}を選択していないという事実がy=0PlotRangePaddingによって範囲に持ち込まれているという意味だと思いFrame -> {{Automatic, None}, {Automatic, None}}

を(ように。

5

座標値にかかわらず、以下のようにAxesを左下に描画します:

ここでは
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] 

enter image description here

aPlot[Sin[x], {x, 0, 2 Pi}] 

enter image description here

+0

+1 Handy! ----- – Simon

+0

@ belisarius:私はあなたのソリューションとAlexey Popkovの派生したソリューションが好きですが、とても複雑で、私がする必要があるアライメントはAxesOrigin - > {0、0} 'である。 Mathematicaにまだ組み込まれていないようなことは悪いことです。 –

+0

@Mike必要なのは{0,0}のケースだけですが、明らかに 'AxesOrigin'が行く方法です! –

1

(このオプションのhere興味深い議論を参照)DisplayFunctionオプションを使用していますベリサリウスのコードに基づいて(IMO)よりエレガントな方法です:

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

両方の方法の唯一の欠点は、AbsoluteOptions does not always give correct value of PlotRangeです。解決策は、(追加PlotRangePaddingの明示的な値と完全PlotRangeを与える)the Ticks hackを使用することです:

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 

completePlotRange[plot_] := 
[email protected]@ 
    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]]] 

このコードは正確に単にFrame -> {{Automatic, None}, {Automatic, None}}, Axes -> Falseを指定するのと同じレンダリングを与えることに注意することは興味深いことです

+0

私はPlotRangeの異常について知っていましたが、私はそれがいくつかのPlot []のいとこに関係していると思っていましたが、Plot []自身には関係していませんでした。 –