Best way to plot doublelog data with 0 values?
27 次查看(过去 30 天)
显示 更早的评论
Dear all,
I'm actually a beginner in Matlab and I want to use it to plot simulation data for my Master Thesis. Right now I want to plot neutron spectra resulting from simulations.
Probably not so important for you, but:
These spectra are normalized per primary particle. The y axis is the differential fluence in energy and the x axis is the energy range (which was binned in the simulation). Since the results are in binned form I have to take a stair plot.
My problem is to display values which are zero. I have read much about it and I know that log(0) is infinitely small, however what would be the best way to display my data? If i take a linear scale I will, of course, not see the variation in small values. If I take log this is somewhat misleading since one could interpret 0 values as non-zero values. Does anyone know how this problem is typically solved in Science? Is there a convention about how to treat such things? Could I somehow set the x-axis on the lowest values (0) so that it would be the ground line and I then mention that the groundline has to be interpreted as 0???
This is my Matlab Input:
---
clear all;
clear all;
clc
figure
A=load('File1.txt');
B=load ('File2.txt');
set(gca,'YScale','log');
stairs(B(:,1),A(:,1));
ylim([0 inf])
--
However, note that the input is not so important, it was just for me to get a plot and then trying to play with it in the editor window rather than inducing changes by changing the code. The .txt files are both single column vectors.
I would be very thankful to hear some proper suggestions from you and thank you already for your time.
Kind regards,
Niklas
3 个评论
dpb
2020-2-27
编辑:dpb
2020-2-27
It perhaps would help to know something more about what the actual data ranges are and what it is that is to be considered the important feature to be illustrated by the plot.
As you've alluded to, the log axis will amplify the extremes of the data visually over a linear scale; this is quite commonly used when data are such that their natural range does cover multiple orders of magnitude. OTOH, Guillaume is absolutely correct in that there simply is no way to accurately represent values that are identically zero on a logarithmic axis--they're off in space in whichever direction the (negative) axis is pointing.
If there is structure in a dataset around the origin or other location that is masked by the overall range of the data on a linear scale, oftentimes the presentation method used is to provide an inset of that section of that data with an enlarged scale. Same idea as the inset on a map for city streets.
回答(1 个)
Prabhan Purwar
2020-3-2
Hi,
kindly try to project the data upon the shifted logarithmic scale, it will help you in representing sparse data as well as zero value for zero input. I am assuming that data consists of only positive values.
Hope it helps!!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!