【发布时间】:2011-06-01 16:58:06
【问题描述】:
我还有一个关于 Wolfram Mathematica 的问题。有没有人知道如何在 y 轴上绘制图形?
希望对图有所帮助。
【问题讨论】:
-
如果您需要
Filling选项,我会更新我的答案。
标签: function wolfram-mathematica plot
我还有一个关于 Wolfram Mathematica 的问题。有没有人知道如何在 y 轴上绘制图形?
希望对图有所帮助。
【问题讨论】:
Filling 选项,我会更新我的答案。
标签: function wolfram-mathematica plot
ParametricPlot[{5 Sin[y], y}, {y, -2 \[Pi], 2 \[Pi]},
Frame -> True, AxesLabel -> {"x", "y"}]
编辑
到目前为止,没有一个答案可以与 Plot 的 Filling 选项一起使用。在这种情况下,Plot 的输出包含 GraphicsComplex(顺便说一下,这会破坏 Mr.Wizard 的替换)。要获得填充能力(它不适用于没有填充的标准图),您可以使用以下内容:
Plot[Sin[x], {x, 0, 2 \[Pi]}, Filling -> Axis] /. List[x_, y_] -> List[y, x]
Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, Filling -> {1 -> {2}}]
/. List[x_, y_] -> List[y, x]
【讨论】:
您可以在使用Reverse 绘制后翻转轴:
g = Plot[Sin[x], {x, 0, 9}];
Show[g /. x_Line :> Reverse[x, 3], PlotRange -> Automatic]
稍作改动,这也适用于使用 Filling 的绘图:
g1 = Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}];
g2 = Plot[{Sin[x], .5 Sin[2 x]}, {x, 0, 2 \[Pi]}, Filling -> {1 -> {2}}];
Show[# /. x_Line | x_GraphicsComplex :> x~Reverse~3,
PlotRange -> Automatic] & /@ {g1, g2}
(用MapAt[#~Reverse~2 &, x, 1]替换:>的RHS可能更健壮)
这是我推荐的一种形式。它包括翻转原来的PlotRange,而不是强制PlotRange -> All:
axisFlip = # /. {
x_Line | x_GraphicsComplex :>
MapAt[#~Reverse~2 &, x, 1],
x : (PlotRange -> _) :>
x~Reverse~2 } &;
用于:axisFlip @ g1 或 axisFlip @ {g1, g2}
Rotate 可以产生不同的效果:
Show[g /. x_Line :> Rotate[x, Pi/2, {0,0}], PlotRange -> Automatic]
【讨论】:
一种可能性是像这样使用ParametricPlot:
ParametricPlot[
{-y*Exp[-y^2], y}, {y, -0.3, 4},
PlotRange -> {{-2, 2}, All},
AxesLabel -> {"x", "y"},
AspectRatio -> 1/4
]
【讨论】:
只是为了好玩:
ContourPlot 是另一种选择。 使用 Thies 函数:
ContourPlot[-y*Exp[-y^2/2] - x == 0,
{x, -2, 2}, {y, 0, 4},
Axes -> True, Frame -> None]
RegionPlot是另一个
RegionPlot[-y*Exp[-y^2/2] > x,
{x, -2.1, 2.1}, {y, -.1, 4.1},
Axes -> True, Frame -> None, PlotStyle -> White,
PlotRange -> {{-2, 2}, {0, 4}}]
最后,使用ListCurvePathPlot 和Solve 的真正令人费解的方式:
Off[Solve::ifun, FindMaxValue::fmgz];
ListCurvePathPlot[
Join @@
Table[
{x, y} /. Solve[-y*Exp[-y^2/2] == x, y],
{x, FindMaxValue[-y*Exp[-y^2/2], y], 0, .01}],
PlotRange -> {{-2, 2}, {0, 4}}]
On[Solve::ifun, FindMaxValue::fmgz];
离题
回复 Sjoerd 的None of the answers given thus far can work with Plot's Filling option。
回复:不需要
f={.5 Sin[2 y],Sin[y]};
RegionPlot[Min@f<=x<=Max@f,{x,-1,1},{y,-0.1,2.1 Pi},
Axes->True,Frame->None,
PlotRange->{{-2,2},{0,2 Pi}},
PlotPoints->500]
【讨论】:
RegionPlot,但它的语法与Plot不同,而且更复杂。能简单加一下就比较熟悉了:Filling -> True
AxesStyle -> Thickness[.1],结果非常好
根据您希望轴标签的显示方式,您可以将原始 Plot 的代码包装在 Rotate 函数中。
【讨论】: