LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Log axis

Solved!
Go to solution

Hello,

 

I am a bit puzzled by the scaling of my log scale...

 

Say the range is -.2 (or zero) to 17788.

 

1) Changing the map mode to log I would have expected an error, according to the documentation:

 

Use a logarithmic scale for the graph axis. The minimum axis value must be greater than zero.

 

Obviously, it must not.

 

2) Having the axis autoscaled, the smallest label is 18, with intermediate labels of 100, 1000, 10000, and the largest label is 17788.

 

Why is the smallest label 18 and not 10, or 1, or 0.1??

 

I have Auto Divisions but no Loose Fit.

 

Thanks, Wolfgang

 

0 Kudos
Message 1 of 11
(6,405 Views)

Hi Wolfgang

 

 

I can’t follow your description. Can you post some screenshoot? It´s easier for me

to follow your step´s when I can see what you mean.

Please let me know which version of CVI you use.

When you want you can also write in German. I’m from Munich.

Best regards
Bernhard

0 Kudos
Message 2 of 11
(6,403 Views)

Hello Bernhard,

 

thank you for your reply. I am attaching two screenshots meant to illustrate my point: The left one is a linear scale, the right one the identical graph with map mode set to logarithmic scale. I am using CVI 2010.

lin_scale.pnglog_scale.png

0 Kudos
Message 3 of 11
(6,392 Views)

If you attempt to set the min to zero or a negative value while in log mode or if you have zero or a negative value for you min then switch to log mode, it coerces the value to a positive number. The reason it is coerced to 18 is because this is the max divided by 1000 (rounded). You do get an error if you attempt to do this in the Edit Graph dialog.

 

If you are switching between linear and log mode, I would recommend also explicitly defining your y-axis if you are not using auto-scale.

National Instruments
0 Kudos
Message 4 of 11
(6,387 Views)

Hi Darren,

 

I am using autoscale, so the minimum and maximum values are given by the data plots assigned to this axis.

 

I agree that it is reasonable to coerce the minimum axis value to a positive value rather than issuing an error - but that's not what the documentation says Smiley Wink

 

I understand your argument why 18 is chosen as minimum value and not 16 - but I do not understand why the value is so 'large': why not 1.8 or 0.18? What is the criterion for autoscale to choose the minimum value?

 

Phrased differently: in case of negative numbers the smallest axis value still depends on the negative minimum number - it is not simply coerced to a certain fraction of the maximum.

 

Why do I care: The practical reason is that in event counting spectra there is a baseline/offset (which is positive). Now if you do offset correction the average value will be around zero, but there will be small negative and positive values. I wouldn't mind to 'loose' the negative values on a log scale, but right now this baseline disappears completely from the graph because the minimum autoscale value is chosen too large...

 

Wolfgang

0 Kudos
Message 5 of 11
(6,381 Views)

Hi Wolfgang,

 

The reason it is being coerced to such a high value is because you have Loose Fit (ATTR_XLOOSE_FIT_AUTOSCALING) enabled for autoscaling and too high of a Loose Fit AutoScale Unit (ATTR_XLOOSE_FIT_AUTOSCALING_UNIT). The autoscaling unit is the log factor that the autoscaling will use for rounding. You probably have the autoscaling unit set to 2 which is the default. This means that it will round to the next higher for max and next lower for min value that is a factor of 100. This works great for a linear scale, but you can see an obvious problem with this design for log scales. By the very nature of the log scale, it does not make sense to round based on the same factor.

 

The reason you are getting a min value of 18 is because the true min of the data is smaller than the autoscaling loose fit factor. And since it cannot use 0 as the min since it is an invalid value for log, it instead defaults to 1/1000 of the max.

 

There are a few issues here with loose fit on a log scale, so I have filed a bug report that you can track with ID: 352509.

 

In the meantime, I found that disabling loose fit allows the autoscale to work correctly even with negative data values. However, if you want to have a loose fit (i.e. you min and max on the scale have a buffer around the min and max of the data), then you will have to implement this yourself. You can use autoscaling when plotting data to automatically detect the max and min of the data, then switch to a fixed scale so that you can then add the buffer region to create a loose fit. Or you can leave autoscaling off and calculate the min and max values yourself.

National Instruments
0 Kudos
Message 6 of 11
(6,360 Views)

Hi Darren,

 

at first sight I was impressed by your detailed analysis - until I realized that it is based on a false assumption...Smiley Surprised

 


I have Auto Divisions but no Loose Fit.


xygraph.png

 

So actually I do not follow your statement that "disabling loose fit allows the autoscale to work correctly even with negative data values" - unfortunately.

 

But your comment made me curios and so I enabled Loose Fit, but I did observe the very same behavior, i.e. an axis range starting at 18... The same result when I changed Loose Fit Units from 2 to 3....

0 Kudos
Message 7 of 11
(6,354 Views)
Solution
Accepted by Wolfgang

Hey Wolfgang,

 

I realized after I posted that you mentioned you were not using loose fit in your first post, but figured I had time to come up with my next response since you are in a different time zone! I see that I can't escape the watchful eye of Wolfgang.

 

What had happend is that in testing this, I was changing to log scale before plotting which is not the issue you are having if I understand it correctly.

 

The problem is that once you plot the data in linear mode, the negative values are plotted on the graph. When you switch to log mode, we do not remove these negative values from the dataset which causes the autoscale min to have an invalid value for log. In the case of an invalid value, we default to 1/1000 the max. If you were to already be in log mode and plot your data, then it properly handles the negative values for log and thus they do not get considered for autoscaling.

 

When switching to log scale, you should delete your current plots and replot them. This will allow the graph to properly handle the negative values for log plotting.

National Instruments
Message 8 of 11
(6,351 Views)

Hi Darren,

 

Thanks, this sounds much better... because it explains the factor 1/1000 and even provides a workaround. Very nice, I'll try it tonight, thanks!

 

Just for future reference, your last sentence would be useful to have in the CVI help; you can cut and paste it from below Smiley Wink :

 

When switching to log scale with an existing dataset with zero or negative values, the current plot should be deleted and replotted. This will allow the graph to properly handle the negative values for log plotting.

0 Kudos
Message 9 of 11
(6,339 Views)

From my side also thanks for this information.

Best regards

Bernhard

0 Kudos
Message 10 of 11
(6,335 Views)