两个 y 轴与相同的 x 轴
可能的重复:
在单个图中绘制 4 条曲线,其中 3 条y 轴
假设我在 Matlab 中有以下数据集作为示例:
x = linspace(0, 9, 10);
y1=arrayfun(@(x) x^2,x);
y2=arrayfun(@(x) 2*x^2,x);
y3=arrayfun(@(x) x^4,x);
因此您可以看到它们具有相同的 x 轴。现在我想要下面的图:
一个 x 轴的限制为 0 到 9(这些限制也应该是刻度),有 N 个刻度(我希望能够自己定义 N),因此中间有 N-2 个刻度,因为 0 和9 本身已经是刻度。我希望 y1 和 y2 引用相同的 y 轴,该轴显示在左侧,并带有 0 和 max([y1, y2]) 的刻度以及中间的 M 个刻度。 比我想在右侧有另一个轴,其中 y3 指的是...
y1、y2 和 y3 应该在同一个图例框中有条目... 到目前为止谢谢!
编辑:argh刚刚发现这个:绘制4条曲线在一个图中,有 3 个 y 轴 也许我可以自己构建它......我现在就尝试!
编辑:使用对数 x 轴时会怎样?!
Possible Duplicate:
Plotting 4 curves in a single plot, with 3 y-axes
assuming I have the following dataset as an example here in Matlab:
x = linspace(0, 9, 10);
y1=arrayfun(@(x) x^2,x);
y2=arrayfun(@(x) 2*x^2,x);
y3=arrayfun(@(x) x^4,x);
thus you can see they have the SAME x-axis. Now I want the following plot:
one x-axis with the limits 0 to 9 (those limits should also be ticks) with N ticks (I want to be able to define N myself), thus having N-2 ticks inbetween because 0 and 9 itself are already ticks. I want y1 and y2 to refer to the same y-axis, which is being displayed on the left with ticks for 0 and max([y1, y2]) and M more ticks inbetween.
than I want to have another axis on the right, where y3 refers to...
y1, y2 and y3 should have entries in the same legend box...
thanks so far!
edit: argh just found this: Plotting 4 curves in a single plot, with 3 y-axes perhaps I can bould it up myself... I will try just right now!
EDIT: What when using logarithmic x-axis?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅有关使用多个 X 轴和 Y 轴的文档。像这样的事情应该可以解决问题:
编辑:哎呀,错过了保持命令。现在应该可以工作了。此外,要删除顶部的第二个 x 轴,只需将
'XTickLabel',[]
添加到axes
命令即可。顺便说一句,您确实不应该将
arrayfun
用于y1=arrayfun(@(x) x^2,x);
。相反,请使用.^
运算符:y1=x.^2;
。它的风格更好,速度也更快。See this documentation on Using Multiple X- and Y-Axes. Something like this should do the trick:
Edit: whoops, missed a hold command. Should work now. Also, to remove the second x-axis on top, simply add
'XTickLabel',[]
to theaxes
command.As an aside, you really shouldn't use
arrayfun
fory1=arrayfun(@(x) x^2,x);
. Instead, use the.^
operator:y1=x.^2;
. It's much better style and is much quicker.