Discussion:
Problem of 'set(gca, 'yscale', 'log')'
(too old to reply)
Yuxiang Lin
2010-02-17 06:22:05 UTC
Permalink
I used the following code to plot F. Everything went well until the last line was executed. The warning message 'Warning: Negative data ignored' popped up and the image totally went wrong. I double-checked the values of 'd' and was pretty sure that it was greater than 0.

Would anybody please help me figure this out? Thank you very much!

N = 1000;
t = 3e-9;
d = 0.0001:0.01:1;
w = logspace(-3, 1, 101)/t;

[D, W] = meshgrid(d, w);
S = sqrt((D.*((2*pi./W).^2+4*(pi*t)^2).^2.*(2*pi*D.*...
((2*pi./W).^4+20*((2*pi./W)*pi*t).^2+64*(pi*t)^4)-(2*pi./W).^2.*((2*pi./W).^2+12*(pi*t)^2).*...
sin(2*pi*D))) ./ ...
(16*N*(2*pi./W).^4*pi.*((2*pi./W).^2+16*(pi*t)^2).*sin(pi*D).^2));
F = S*sqrt(N)/t;

figure(1)
imagesc(d, w*t, log10(F));
set(gca, 'yscale', 'log')
Hyatt
2011-02-23 23:03:07 UTC
Permalink
I did not get the error with what you had here. It's a pretty picture if you don't change the scale to be logarithmic. You are getting negative values from your log10(F) call however, which I imagine is causing the warning of negative values (in the color) being ignored. You could try setting a different color profile as well - maybe jet or hot for example - this won't fix the negative color problem but may be why your results are not looking how you expect.

You could also put in min(1,max(0,log10(F))) to clip your color values to [0,1].
Post by Yuxiang Lin
I used the following code to plot F. Everything went well until the last line was executed. The warning message 'Warning: Negative data ignored' popped up and the image totally went wrong. I double-checked the values of 'd' and was pretty sure that it was greater than 0.
Would anybody please help me figure this out? Thank you very much!
N = 1000;
t = 3e-9;
d = 0.0001:0.01:1;
w = logspace(-3, 1, 101)/t;
[D, W] = meshgrid(d, w);
S = sqrt((D.*((2*pi./W).^2+4*(pi*t)^2).^2.*(2*pi*D.*...
((2*pi./W).^4+20*((2*pi./W)*pi*t).^2+64*(pi*t)^4)-(2*pi./W).^2.*((2*pi./W).^2+12*(pi*t)^2).*...
sin(2*pi*D))) ./ ...
(16*N*(2*pi./W).^4*pi.*((2*pi./W).^2+16*(pi*t)^2).*sin(pi*D).^2));
F = S*sqrt(N)/t;
figure(1)
imagesc(d, w*t, log10(F));
set(gca, 'yscale', 'log')
Steven_Lord
2011-02-24 16:55:29 UTC
Permalink
Post by Hyatt
I did not get the error with what you had here. It's a pretty picture if
you don't change the scale to be logarithmic. You are getting negative
values from your log10(F) call however, which I imagine is causing the
warning of negative values (in the color) being ignored. You could try
setting a different color profile as well - maybe jet or hot for example -
this won't fix the negative color problem but may be why your results are
not looking how you expect.
This is not the cause of the problem, I believe.

To the OP: execute all your code up to but not including the command that
changes the scale to 'log'. Now look at the limits of your Y axis.

ylim

Remember that IMAGESC, like IMAGE, uses the x and y inputs as the _centers_
of the pixels. Because the smallest element of w*t is so small, the pixels
corresponding to that coordinate extend into the region of the plane where
the y coordinate is barely negative, and this causes the limits of the axes
to be just slightly negative. When you set the YScale to be a logarithmic
scale, that slight section of the axes where the Y coordinate is negative
causes this warning.
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
TideMan
2011-02-24 19:20:36 UTC
Permalink
Post by Steven_Lord
I did not get the error with what you had here.  It's a pretty picture if
you don't change the scale to be logarithmic.  You are getting negative
values from your log10(F) call however, which I imagine is causing the
warning of negative values (in the color) being ignored.  You could try
setting a different color profile as well - maybe jet or hot for example -
this won't fix the negative color problem but may be why your results are
not looking how you expect.
This is not the cause of the problem, I believe.
To the OP:  execute all your code up to but not including the command that
changes the scale to 'log'.  Now look at the limits of your Y axis.
ylim
Remember that IMAGESC, like IMAGE, uses the x and y inputs as the _centers_
of the pixels.  Because the smallest element of w*t is so small, the pixels
corresponding to that coordinate extend into the region of the plane where
the y coordinate is barely negative, and this causes the limits of the axes
to be just slightly negative.  When you set the YScale to be a logarithmic
scale, that slight section of the axes where the Y coordinate is negative
causes this warning.
--
Steve Lord
To contact Technical Support use the Contact Us link onhttp://www.mathworks.com
Steven

I disagree with you.
I think the problem is that the OP has log10(F) as his y-axis, then
told Matlab he wants the axis to be logarithmic. In other words,
Matlab tries to use log10(log10(F)) on the y-axis.
OP can fix the problem by doing this:
imagesc(d, w*t, F);
set(gca, 'yscale', 'log')

or this:
imagesc(d, w*t, log10(F));
ytick=get(gca,'YTick')';
set(gca,...
'YTicklabel',num2str(10.^ytick))

and relabeling the yticks as 10.^yticks
Steven_Lord
2011-02-24 19:58:32 UTC
Permalink
Post by TideMan
Post by Steven_Lord
Post by Hyatt
I did not get the error with what you had here. It's a pretty picture if
you don't change the scale to be logarithmic. You are getting negative
values from your log10(F) call however, which I imagine is causing the
warning of negative values (in the color) being ignored. You could try
setting a different color profile as well - maybe jet or hot for example -
this won't fix the negative color problem but may be why your results are
not looking how you expect.
This is not the cause of the problem, I believe.
To the OP: execute all your code up to but not including the command that
changes the scale to 'log'. Now look at the limits of your Y axis.
ylim
Remember that IMAGESC, like IMAGE, uses the x and y inputs as the _centers_
of the pixels. Because the smallest element of w*t is so small, the pixels
corresponding to that coordinate extend into the region of the plane where
the y coordinate is barely negative, and this causes the limits of the axes
to be just slightly negative. When you set the YScale to be a logarithmic
scale, that slight section of the axes where the Y coordinate is negative
causes this warning.
--
Steve Lord
To contact Technical Support use the Contact Us link
onhttp://www.mathworks.com
Steven
I disagree with you.
I think the problem is that the OP has log10(F) as his y-axis, then
told Matlab he wants the axis to be logarithmic. In other words,
Matlab tries to use log10(log10(F)) on the y-axis.
I have to disagree with your disagreement. The exact line of code the user
executes, from the first message I see in this thread, is:

imagesc(d, w*t, log10(F));

From the signature of IMAGESC as given in the documentation:

http://www.mathworks.com/help/techdoc/ref/imagesc.html

"imagesc(x,y,C) displays C as an image and specifies the bounds of the x-
and y-axis with vectors x and y."

log10(F) is the user's image data [the C input]. d controls the x
coordinates of the pixel centers. w*t controls the y coordinates of the
pixel centers. It is w*t that has values so small that the extent of the
pixel includes points with negative y coordinates and it is that which
causes the warning.

To check this, let's take the log10(F) out of the picture entirely.


N = 1000;
t = 3e-9;
d = 0.0001:0.01:1;
w = logspace(-3, 1, 101)/t;

[D, W] = meshgrid(d, w);

% Execute these blocks one at a time. The first should warn and the second
should not
figure
imagesc(d, w*t, ones(size(D)))
set(gca, 'YScale', 'log') % should warn

figure
imagesc(d, 0.1+w*t, -ones(size(D)))
set(gca, 'YScale', 'log') % should not warn
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
TideMan
2011-02-24 20:09:16 UTC
Permalink
Post by TideMan
Post by Steven_Lord
I did not get the error with what you had here.  It's a pretty picture if
you don't change the scale to be logarithmic.  You are getting negative
values from your log10(F) call however, which I imagine is causing the
warning of negative values (in the color) being ignored.  You could try
setting a different color profile as well - maybe jet or hot for example -
this won't fix the negative color problem but may be why your results are
not looking how you expect.
This is not the cause of the problem, I believe.
To the OP:  execute all your code up to but not including the command that
changes the scale to 'log'.  Now look at the limits of your Y axis.
ylim
Remember that IMAGESC, like IMAGE, uses the x and y inputs as the _centers_
of the pixels.  Because the smallest element of w*t is so small, the pixels
corresponding to that coordinate extend into the region of the plane where
the y coordinate is barely negative, and this causes the limits of the axes
to be just slightly negative.  When you set the YScale to be a logarithmic
scale, that slight section of the axes where the Y coordinate is negative
causes this warning.
--
Steve Lord
To contact Technical Support use the Contact Us link
onhttp://www.mathworks.com
Steven
I disagree with you.
I think the problem is that the OP has log10(F) as his y-axis, then
told Matlab he wants the axis to be logarithmic.  In other words,
Matlab tries to use log10(log10(F)) on the y-axis.
I have to disagree with your disagreement.  The exact line of code the user
    imagesc(d, w*t, log10(F));
http://www.mathworks.com/help/techdoc/ref/imagesc.html
"imagesc(x,y,C) displays C as an image and specifies the bounds of the x-
and y-axis with vectors x and y."
log10(F) is the user's image data [the C input].  d controls the x
coordinates of the pixel centers.  w*t controls the y coordinates of the
pixel centers.  It is w*t that has values so small that the extent of the
pixel includes points with negative y coordinates and it is that which
causes the warning.
To check this, let's take the log10(F) out of the picture entirely.
N = 1000;
t = 3e-9;
d  = 0.0001:0.01:1;
w = logspace(-3, 1, 101)/t;
[D, W] = meshgrid(d, w);
% Execute these blocks one at a time.  The first should warn and the second
should not
figure
imagesc(d, w*t, ones(size(D)))
set(gca, 'YScale', 'log') % should warn
figure
imagesc(d, 0.1+w*t, -ones(size(D)))
set(gca, 'YScale', 'log') % should not warn
--
Steve Lord
To contact Technical Support use the Contact Us link onhttp://www.mathworks.com
Aaah.......
You're right.
I don't use image a lot (at all, in fact).
Hadi
2017-07-25 17:44:12 UTC
Permalink
Post by Steven_Lord
Post by TideMan
Post by Steven_Lord
This is not the cause of the problem, I believe.
To the OP: execute all your code up to but not including the command that
changes the scale to 'log'. Now look at the limits of your Y axis.
ylim
Remember that IMAGESC, like IMAGE, uses the x and y inputs as the _centers_
of the pixels. Because the smallest element of w*t is so small, the pixels
corresponding to that coordinate extend into the region of the plane where
the y coordinate is barely negative, and this causes the limits of the axes
to be just slightly negative. When you set the YScale to be a logarithmic
scale, that slight section of the axes where the Y coordinate is negative
causes this warning.
--
Steve Lord
To contact Technical Support use the Contact Us link
onhttp://www.mathworks.com
Steven
I have to disagree with your disagreement. The exact line of code the user
imagesc(d, w*t, log10(F));
http://www.mathworks.com/help/techdoc/ref/imagesc.html
"imagesc(x,y,C) displays C as an image and specifies the bounds of the x-
and y-axis with vectors x and y."
log10(F) is the user's image data [the C input]. d controls the x
coordinates of the pixel centers. w*t controls the y coordinates of the
pixel centers. It is w*t that has values so small that the extent of the
pixel includes points with negative y coordinates and it is that which
causes the warning.
To check this, let's take the log10(F) out of the picture entirely.
N = 1000;
t = 3e-9;
d = 0.0001:0.01:1;
w = logspace(-3, 1, 101)/t;
[D, W] = meshgrid(d, w);
% Execute these blocks one at a time. The first should warn and the second
should not
figure
imagesc(d, w*t, ones(size(D)))
set(gca, 'YScale', 'log') % should warn
figure
imagesc(d, 0.1+w*t, -ones(size(D)))
set(gca, 'YScale', 'log') % should not warn
--
Steve Lord
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
So, is there a solution to make this work with imagesc, or is there another function that acts like imagesc and doesn't use corners to interpret the pixel color. Because pcolor and surf don't have this problem.

Thanks,

Loading...