如何在mathematica中自动生成函数名?
当我绘制多个函数(例如 exp,2^x,3^x)时,是否可以生成每个函数的标签?
我现在的代码:
Plot[{Exp[x], 2^x, 3^x}, {x, -5, 2}, AspectRatio -> Automatic, PlotStyle -> {Red, Green, Blue}]
我的意思是在本例中生成 3 个标签来告诉用户它是什么功能。
如:
如何生成这个?
When I draw multiple functions like exp,2^x,3^x, is it possible to generate a label of each function?
My code now:
Plot[{Exp[x], 2^x, 3^x}, {x, -5, 2}, AspectRatio -> Automatic, PlotStyle -> {Red, Green, Blue}]
What I mean is generate 3 labels in this case to tell the user what function it is.
Such as:
How do you generate this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许这可行:在
Plot
中使用Tooltip
生成带有工具提示的Graphics
对象。然后重写工具提示,将所需的文本放置在所需的位置:Perhaps this works: Use
Tooltip
inPlot
to generate aGraphics
object with tooltips. Then rewrite the tooltip to place the desired text in the desired location:我不确定为同一问题添加另一个不同答案的规则是什么。但这是另一种不同的方法。如果我应该将其添加到我的第一个答案中,我可以这样做。
您可以使用文本命令手动添加文本标签。我认为它看起来更好。这是一种方法:
绘制最终结果(在绘制范围中添加一些填充,以便
添加的标签完全可见)
更新 (1)
Sam 在下面询问一个更简单的方法。我现在不确定。但更容易使用此方法的一种方法是创建一个函数,然后只需调用该函数一次即可生成文本标签。您可以将此函数放在您经常使用的所有其他函数的位置,然后调用它。
这是这样的:首先编写函数
,现在只要您想使用标签进行绘图,就可以调用上面的函数。只需要额外增加 1-2 行代码。像这样:
以下是一些示例:
您可以根据需要进行修改。
I am not sure what the rules are for adding another, different answer for the same question. But here is another, different way to do it. If I am supposed to add this to my first answer, I can do that.
You can add the text labels, by hand, using Text commands. I think it looks better. Here is one way:
Plot the final result (added a little of padding to plot range so that
the labels added are seen completely)
update (1)
Sam asked below for an simpler way. I am not sure now. But one way to make it easier to use this method, is to make a function and then simply call this function once to generate the Text labels. You can put this function where you put all your other functions you use all the time, and just call it.
Here is something: First write the function
And now just call the above any time you want to plot with labels. It will be just 1-2 extra lines of code. like this:
Here are few examples:
You can modify it as you want.
当鼠标指针位于函数图上时使用
Tooltip
显示标签的替代方法:Alternative way with
Tooltip
displaying labels while the mouse pointer is at the function graphs :一种方法是使用
PlotLegends
(我不太喜欢它,但这是一种简单的方法来实现你想要的)
查看帮助以进一步自定义图例。上面使用默认值。
http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLegends。 html
One way is to use
PlotLegends
(I do not like it too much, but it is an easy way to do what you want)
see help to customize the legend more. The above uses defaults.
http://reference.wolfram.com/mathematica/PlotLegends/tutorial/PlotLegends.html