【问题标题】:plotting on the y-axis in Mathematica在 Mathematica 的 y 轴上绘图
【发布时间】:2011-06-01 16:58:06
【问题描述】:

我还有一个关于 Wolfram Mathematica 的问题。有没有人知道如何在 y 轴上绘制图形?

希望对图有所帮助。

【问题讨论】:

  • 如果您需要Filling 选项,我会更新我的答案。

标签: function wolfram-mathematica plot


【解决方案1】:
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]

【讨论】:

  • @Thies 那里是一片丛林 ;-)
  • @Thies 显然,成为第一也无济于事(即使只有 2 分钟)。你的被接受了。
  • @Sjoerd 我知道函数逆向工程技术有一天会派上用场;)
  • 我已经投了这个票,所以我不能再投了,但是很好的更新!
  • @Sjoerd 小心避开的区域在我的 Lebesgue 标尺中测量为零
【解决方案2】:

您可以在使用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 @ g1axisFlip @ {g1, g2}


Rotate 可以产生不同的效果:

Show[g /. x_Line :> Rotate[x, Pi/2, {0,0}], PlotRange -> Automatic]

【讨论】:

  • +1 我觉得包含填充的版本应该是明确的答案。 Rotate 版本的错误与 Alexey 的相同:y 符号错误。
【解决方案3】:

一种可能性是像这样使用ParametricPlot

ParametricPlot[
  {-y*Exp[-y^2], y}, {y, -0.3, 4},
  PlotRange -> {{-2, 2}, All},
  AxesLabel -> {"x", "y"},
  AspectRatio -> 1/4
]

【讨论】:

    【解决方案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}}]
    

    最后,使用ListCurvePathPlotSolve真正令人费解的方式:

    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 -&gt; True
    • @Mr.真的!但这只是我们和 Sjoerd 一起玩的一个小玩笑 :)
    • 是的@mr.Wizard,不要破坏我们的乐趣。这是我们的斗智斗勇。
    • @Sjoerd 你不应该嘲笑我的努力。我现在正在探索AxesStyle -&gt; Thickness[.1],结果非常好
    【解决方案5】:

    根据您希望轴标签的显示方式,您可以将原始 Plot 的代码包装在 Rotate 函数中。

    【讨论】:

      猜你喜欢
      • 2013-12-22
      • 2016-06-24
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多