Mathematica 操作图:缩放轴
假设我已经设置了以下函数 f[a,b,c]
,我希望在改变 a
和 b
时绘制
f[a_,b_,c_]:=a b c Exp[a b]
Manipulate[
Plot
[
f[a,b,c],
{c,0,1},
PlotRange->{{0,0.05},Automatic}
],
{a,0,1},
{b,0,1}
]
它是否可能当我固定横坐标观看范围时,纵坐标会自动缩放吗?您会注意到上面的代码,当改变 a
和 b
时,纵坐标会自动缩放,就像我正在查看 < 的整个范围一样。代码>{c,0,1}。我希望它仍然能够处理从 0 到 1 的 c
,但是如果我想查看该图的较小部分,例如从 0 到 0.05 的 c
,仍然可以垂直轴缩放正确。谢谢大家的帮助。
Say I have set up the following function f[a,b,c]
which I wish to plot while varying a
and b
f[a_,b_,c_]:=a b c Exp[a b]
Manipulate[
Plot
[
f[a,b,c],
{c,0,1},
PlotRange->{{0,0.05},Automatic}
],
{a,0,1},
{b,0,1}
]
Is it possible to have the ordinate scaled automatically when I fix the abscissa viewing range? You'll notice with the code above that when varying a
and b
the ordinate does scale automatically as if I were viewing the whole range of {c,0,1}
. I would like it to still handle c
from 0 to 1, but if I want to view a smaller section of this plot, say c
from 0 to 0.05, still have the vertical axis scaled correctly. Thank you all for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Artes Docendo 建议的一个变体:
注意
Evaluate
强制将机器精度值提供给Plot
函数,然后再实际尝试绘制某些内容。在这种情况下,对于 y 轴
PlotRange
,我更喜欢使用Full
而不是Automatic
,因为那样你就知道它永远不会以某种方式裁剪绘图隐藏部分曲线。A variant on Artes Docendo's suggestion:
Notice the
Evaluate
to force the machine-precision value to be fed to thePlot
function before it actually tries to draw something.I prefer
Full
instead ofAutomatic
for the y-axisPlotRange
in cases like this, because then you know it will never crop the plot in ways that hide parts of the curve.这是许多可能的解决方案之一:
但是您的示例不是很有启发性,要了解它如何更好地工作,请尝试类似的方法
这 :
Here is one of many possible solutions :
However your example is not very instructive, to see how it works better try something like
this :
看看这是否符合您的要求。我只是使用 ListPlot 而不是绘图。
但我不确定你在做什么,因为你正在为 c 从 0 到 1 绘制
f
,然后将 x 范围设置为仅从 0 到 0.05?为什么不直接使用{c,0,0.05}
绘制f
呢?也许我错过了一些东西。无论如何,这就是我
刚刚想到的edit(1)
,为了使上述更有效,是使用第一个 Table 命令,也生成数据本身,而不仅仅是找到绘图范围的最大值/最小值。然后使用
ListPlot
而不是Plot
。这应该更快,这样函数f
的采样只发生一次而不是两次?所以这是第二个版本
See if this does what you want. I simply use ListPlot instead of plot.
But I am not sure what you are doing, as you are plotting
f
for c from 0 to 1, but then setting the x-range to only be from 0 to 0.05? Why not then just plotf
using{c,0,0.05}
? May be I am missing something.Anyway, here is what I have
edit(1)
it just occurred to me, to make the above more efficient, is to use the first Table command, to generate the data itself as well, and not just find the max/min of the plot range. And then use
ListPlot
instead ofPlot
. This should be faster, so that sampling of the functionf
only happens once instead of 2 times?So here is second version