如何在matlab中将'plotyy'中的y轴更改为自然对数刻度

时间:2022-03-18 20:16:04

Unless otherwise stated "log" will refer to natural log.

除非另有说明,否则“log”将指自然日志。

I'm using plotyy in matlab to plot 2 sets of data. The first set is (x,Q), where Q = -ln(y). Note that "ln" here is NOT a function call...it is the expression for the natural log. The second set is (x,q), where q = 1/exp(Q). I want the y-axis of the second set to be presented on a log scale. My function call is

我在matlab中使用plotyy来绘制2组数据。第一组是(x,Q),其中Q = -ln(y)。请注意,这里的“ln”不是函数调用...它是自然日志的表达式。第二组是(x,q),其中q = 1 / exp(Q)。我希望第二组的y轴以对数刻度显示。我的函数调用是

plotyy(x,Q,x,q,'plot','semilogy')

Since semilogy is a base 10, the lines do not overlap. How do I get the y-axis of the second set to be presented on a log scale?

由于半月形是基数10,因此线不重叠。如何在对数刻度上显示第二组的y轴?

I can't touch Q and it is to remain plotted on a linear scale. Changing that is not an option. In the end the plots should be identical where the only thing that changes is the scale on the second y-axis. I will also note that y covers both positive and negative numbers.

我无法触摸Q,它仍然是以线性比例绘制的。改变这不是一种选择。最后,绘图应该是相同的,其中唯一改变的是第二个y轴上的刻度。我还要注意y包括正数和负数。

1 个解决方案

#1


1  

Matlab doesn't offer natural log as scaling of axes. But since your goal is to overlap the left and the right side of the axes, you can simply choose the limits on the right side to be equivalent with the ones on the left:

Matlab不提供自然对数作为轴的缩放。但由于您的目标是重叠轴的左侧和右侧,您可以简单地选择右侧的限制与左侧的限制相同:

ha = plotyy(x,log(y),x,y,'plot','semilogy'); % handles of both axes
leftlim = ylim(ha(1)); % reading ylim of the left side
ylim(ha(2), [exp(leftlim(1)), exp(leftlim(2))]) % changing ylim of the right side

#1


1  

Matlab doesn't offer natural log as scaling of axes. But since your goal is to overlap the left and the right side of the axes, you can simply choose the limits on the right side to be equivalent with the ones on the left:

Matlab不提供自然对数作为轴的缩放。但由于您的目标是重叠轴的左侧和右侧,您可以简单地选择右侧的限制与左侧的限制相同:

ha = plotyy(x,log(y),x,y,'plot','semilogy'); % handles of both axes
leftlim = ylim(ha(1)); % reading ylim of the left side
ylim(ha(2), [exp(leftlim(1)), exp(leftlim(2))]) % changing ylim of the right side