可以将方程的表达式放在其图形表示附近吗?

发布于 2024-08-11 09:52:26 字数 108 浏览 2 评论 0原文

是否有可能当我在 Mathematica 中绘制函数时,它会自动将方程(即 y = 2x)甚至其他文本放在其附近?

乍一看我没有找到任何选项,但如果有的话我想知道。

谢谢

Is it possible that when I Plot a function in Mathematica, it will automatically put near it it's equation(i.e. y = 2x) or even some other text?

At first glance I don't find any option for it, but if there is one I'd like to know.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

留一抹残留的笑 2024-08-18 09:52:26

使用 Mathematica 6 或更高版本时,我经常使用工具提示来帮助我识别绘图曲线:

Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]

唉,这仅在交互式使用图形时才有用,因为您必须将鼠标光标悬停在曲线上。它在纸上或静态图像上效果不太好。

您可以使用Epilog选项在绘图上手动放置一些文本,如本例所示:

Plot[
  Sin[x], {x, 0, 8 Pi},
  Epilog -> Text["My Text", Offset[{32, 0}, {14, Sin[14]}]]
]

根据需要调整Offset的参数。

如果您不介意手动放置,则此方法有效。自动放置会带来一些挑战,具体取决于您希望绘制的函数类型。但是,如果您了解感兴趣的函数的一般特征,您可以编写一个函数来计算 Offset 参数的漂亮值。例如,如果我知道我要绘制大量指数下降函数,我可能会定义类似于此示例中的函数 myPlot 的内容:

SetAttributes[myPlot, HoldAll]
myPlot[function_, {var_, min_, max_}] :=
  Plot[
    function, {var, min, max},
    Epilog -> Text[function, Offset[{40, 0}, {var, function} /. var -> min + (max - min)/20]],
    PlotRange -> All, AxesOrigin -> {0, 0}
  ]

... 其中 Offset 的参数> 使用一些任意常量自动计算,这些常量对于此类绘图相当有效:

Manipulate[
  myPlot[1000 E^(-d t), {t, 0, 100}, "My Label"],
  {d, 0.01, .2}
]

由于所有这些选项都是可编程的,因此您可以为标签放置编写复杂程度的代码是无限的。当然,这样的编程与 Plot 内置选项的理想状态越来越远,后者只是神奇地落在函数旁边的一些文本上。可能是 Mathematica 8 或 9 :)

Using Mathematica 6 or higher, I often use Tooltip to help me identify plot curves:

Plot[Tooltip[Sin[x]], {x, 0, 8 Pi}]

Alas, this is only useful when using the graph interactively since you must hover the mouse cursor over the curve. It doesn't work so well on paper or on a static image.

You can use the Epilog option to manually place some text on the plot, as in this example:

Plot[
  Sin[x], {x, 0, 8 Pi},
  Epilog -> Text["My Text", Offset[{32, 0}, {14, Sin[14]}]]
]

Tweak the arguments of Offset to taste.

This works if you do not mind manual placement. Automatic placement poses some challenges, depending upon the kinds of functions that you wish to plot. But if you know something of the general characteristics of the functions of interest, you could write a function that calculates nice looking values for the Offset arguments. For example, if I knew I was going to plot lots of exponential decline functions, I might define something like the function myPlot in this example:

SetAttributes[myPlot, HoldAll]
myPlot[function_, {var_, min_, max_}] :=
  Plot[
    function, {var, min, max},
    Epilog -> Text[function, Offset[{40, 0}, {var, function} /. var -> min + (max - min)/20]],
    PlotRange -> All, AxesOrigin -> {0, 0}
  ]

... where the arguments to Offset are computed automatically using some arbitrary constants that work reasonably well for these kinds of plots:

Manipulate[
  myPlot[1000 E^(-d t), {t, 0, 100}, "My Label"],
  {d, 0.01, .2}
]

Since all of these options are programmable, the sky's limit as to how much sophistication you could code up for the label placement. Of course, such programming drifts farther and farther away from the ideal of a built-in option to Plot that just magically drops on some text next to the function. Mathematica 8 or 9 maybe :)

请你别敷衍 2024-08-18 09:52:26

实现此目的的一种方法是使用 PlotLegends 标准附加包。默认情况下,输出看起来不太好;我建议设置 LegendShadow -> None 选项并在图例中粘贴的表达式上使用 Style 以使它们看起来更好。此外,加载包会对 Plot 和相关函数造成一些有趣的重新定义,如果您不小心,这些函数可能会破坏其他一些东西。

One way to do this, which automatically associates the expression with the style used to plot it, is to use the PlotLegends standard add-on package. The output doesn't look very good by default; I recommend setting the LegendShadow -> None option and using Style on the expressions you stick in the legend to make them look better. Also, loading the package inflicts some funny redefinitions on Plot and related functions which can break some other things if you're not careful.

ㄖ落Θ余辉 2024-08-18 09:52:26

“接近其方程”就是问题所在。这不是一个容易解决的问题,当您开始获得具有重叠图等的“繁忙”图表时,它就变得有些不可能。

我没有一个很好的例子来展示,但通常我会定义一个“标签函数”,它采用与绘制的函数相同的输入,它在图形上放置一个点并在附近写一些文本。这样做的优点是能够轻松改变文本的位置,但仍然将其与功能联系在一起。

"Near its equation" is the problem. This isn't an easy problem to solve, and it becomes somewhat impossible when you start getting "busy" graphs with overlapping plots and so on.

I don't have a good example to show, but usually I'll define a "labelling function" that takes the same input as the function being plotted, which places a dot on the graph and writes some text nearby. This has the advantage of being able to easily vary the location of the text but still have it tied to the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文