如何在Semilogx图中绘制x = 0? [英] How to plot x=0 in semilogx plot?
问题描述
我需要使用semilogx(x,y)
绘制图形.我有x=[0 1 2 ... 10 15 20 30 50 75 100]
.问题是MATLAB无法绘制x=0
,我理解这是因为log(0)=undef
.那么MATLAB中还有另一种传播观点的方法吗?因为使用线性比例会挤压图宽度的1/10的所有第一点!
I need to plot a graph using semilogx(x,y)
. I have x=[0 1 2 ... 10 15 20 30 50 75 100]
. The problem is that MATLAB does not plot x=0
, which I understand because log(0)=undef
. So is there another method in MATLAB to spread my points? Because using linear scale squeezes all first points in 1/10th of the graph's width!
推荐答案
通常,在这种情况下要做的就是向所有x
添加1
,因此第一个值(最初为0
)出现在所有值的反向转换都是相同的.您可以添加除1
以外的任何其他小值,并获得类似的结果.但是,您不希望添加太小的 值(例如eps
),因为这样会使您与下一个值相距很远,这将导致所有其他值堆积在图的右侧.
Usually, what is done in cases like this is adding 1
to all x
, so the first value (originally 0
) appears at the origin, and also the back-transformation is the same for all values. You can add any other small values than 1
, and get a similar result. However, you don't want to add a value that is too small (like eps
) because then you get a huge distance from the next value, that will cause all other values to pack on the right side of the graph.
让我们看一个例子:
x = [0 logspace(0,2,5)];
% x = 0 1 3.1623 10 31.623 100
y = 2.*(x+1); % add 1 to all x
semilogx(x+1,y,'o','markerfacecolor','b')
如果将0
替换为eps
,则会得到:
While if you replace 0
with eps
you get:
x = [0 logspace(0,2,5)];
y = 2.*(x+eps); % add a tiny value too all x
semilogx(x+eps,y,'o','markerfacecolor','b')
这篇关于如何在Semilogx图中绘制x = 0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!