Warning: Negative data ignored
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sonali
el 20 de En. de 2024
Editada: Walter Roberson
el 21 de En. de 2024
Hi, I am trying to plot multiple plots of different ions, For example,column ion(mean values of ion density), mid (another column) and err(std dev of ion density). Some value are NaN but none negative. I have changed NaN to 0 yet I get an error in the tile "Warning: Negative data ignored" on title or on figure() of the next plot. Please find my prog below:
....................................................................................................................
ion(isnan(ion))=0;
err(isnan(err))=0;
figure()
semilogx((ion),mid,'.g',LineStyle='none',LineWidth=1.5,MarkerSize= 8 )
text(ion(1), 160,'\rightarrow Ion^+','Color','green','Rotation',-90,'FontSize',10)
hold on
errorbar(ion,mid,err,'horizontal',LineStyle='none', Color='g',LineWidth = 0.1,CapSize=2)
grid on
xlabel('Ion')
ylabel('Mid')
xlim([0.005 50])
ylim([80 500])
title('density' ,FontSize=10)
hold off
....................................................................................................................
link to prog and data: https://drive.google.com/drive/folders/111PwK1cC-09H_Pm7aHTJItMKhTaELyb2?usp=drive_link
2 comentarios
Shivam
el 20 de En. de 2024
Hi,
Could you attach the data files using the paperclip icon so I can investigate the issue?
Respuesta aceptada
Shivam
el 21 de En. de 2024
Hi Sonali,
From the information provided, I understand that while plotting multiple plots of different ions, you are getting the warning, 'Warning: Negative data ignored'.
Upon debugging for the csv file: 'mvn_ngi_l2_ion-abund-15138_20150303T010508_v08_r01.csv', I observed that while plotting the second plot, xlim are not set correctly.
You can follow the below workaround to make the only change in your code to remove the warnings:
% ..
text(ion_ar(9), 160,'\rightarrow Ar^+','Color','g','Rotation',-90,'FontSize',10)
hold on;
% Line to be added
xlim([0.0001 5]); % Set the xlim of this plot correctly
errorbar(ion_ar,mid,abs(err_ar),'horizontal',LineStyle='none', Color='g',LineWidth = 0.1,CapSize=2)
% ..
Also, you can suppress the warning by executing the following command in the MATLAB's command window:
>> warning off MATLAB:Axes:NegativeDataInLogAxis
You can refer to the following documentation to know more about "Warning Suppress":
I hope it helps.
Thanks
0 comentarios
Más respuestas (2)
Steven Lord
el 20 de En. de 2024
I believe the error message is technically incomplete. It should probably say something like "Negative and zero data ignored" when you're plotting data that includes either negative numbers or 0 on a log scale.
x = log(0)
Where exactly should this x be plotted on a logarithmic X axis? Do you have an infinitely wide monitor on which to display this point?
If you have X data that is negative or 0 in your data, you need to replace it with a positive number in order to show it on a semilogx axes.
0 comentarios
Sulaymon Eshkabilov
el 20 de En. de 2024
Note that log() of a negative number can't be plotted that is correct. If you want to show their abs values in different color, e.g.:
x = randi([-2 6], 1, 50);
y = sin(x);
% Separation of negative and positive values of x
IDX1 = x>=0;
IDX2 = x<0;
xpos=x(IDX1);
y_xpos = y(IDX1);
xneg = x(IDX2);
y_xneg = y(IDX2);
figure()
semilogx(xpos,y_xpos,'.g','LineStyle','none','LineWidth',1.5,'MarkerSize',10, 'DisplayName', 'x >=0')
hold on
semilogx(abs(xneg),y_xneg,'pr','LineStyle','none','LineWidth',1.5,'MarkerSize',13, 'DisplayName', 'x < 0')
legend('show')
hold off
figure() % See "Warning: Negative data ignored "
semilogx(x,y,'.g','LineStyle','none','LineWidth',1.5,'MarkerSize',10, 'DisplayName', 'x >=0')
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

