LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Logarithmic Binning Histogram

I want to plot the logarithmic binning histogram of a 1D array in LabView.

It means the x-scale is logarithmic and the bins are equally spaced in log10.

I have done it in python and I'm using this Python function in LabView to plot logarithmic binning. But it is not efficient and I want to do it in LabView.

 

Python function:

import numpy as np
import matplotlib.pyplot as plt

def f(data_array):
      mini=min(data_array)
      maxi=max(data_array)

      bins=np.logspace(np.log10(mini), np.log10(maxi), 80)
      widths=(bins[1:] - bins[:-1])

      n, bins, patches=plt.hist(data_array, bins, density=True)

      plt.xscale('log')
      plt.xlabel('interval times(s)')
      plt.ylabel('number')
      return plt.show()

 

My LabView code:

Noa_A_0-1641542256159.png

 

Do you have any idea how can I do that?

 

I can plot a histogram in LabView with Logarithmic x-scale but the bins are not logarithmic:

Noa_A_1-1641542476542.png

 

 

0 Kudos
Message 1 of 18
(4,126 Views)

 go to graph properties. select scales tab then select X-Axis and enable log

graph log.png


CLD Using LabVIEW since 2013
0 Kudos
Message 2 of 18
(4,120 Views)

Kartiknattar,

Thanks for your response, I already have done it. 

As I mentioned I need the bins to be equally spaced in log10.

If I choose the interval a constant number and just choose the x-scale logarithmic, then I will have this:

Noa_A_0-1641543623064.png

This is not what I want. As you see the bins are not equal in the log scale.

 

0 Kudos
Message 3 of 18
(4,113 Views)

Try this example code. It might help you..

 

https://forums.ni.com/t5/Example-Code/Programmatically-Set-A-Graph-Scale-To-Linear-Or-Log/ta-p/35244...


CLD Using LabVIEW since 2013
0 Kudos
Message 4 of 18
(4,110 Views)

For example, by this simple code and choosing x-scale logarithmic but interval as a constant number:

Noa_A_0-1641544307300.png

I will have:

Noa_A_1-1641544336117.png

But with the Python code, for the same array I have:

 

Noa_A_2-1641544705141.png

That is what I want. So the x scale is not the problem, I should do some thing with the interval. but I dont know how. 

In python I have set the bins:

   bins=np.logspace(np.log10(mini), np.log10(maxi), 80)

so, the intervals of the bins are Logarithmic. 

 

0 Kudos
Message 5 of 18
(4,105 Views)

Actually, my Python code had some problems 😁, The correct one is this:

   data=[10, 10, 100, 2, 2, 10, 10, 1, 1, 100, 10, 10, 50, 50, 50, 50, 100, 100, 100]
   maxi=max(data)
   mini=min(data)

   pl.hist(data, bins=np.logspace(np.log10(mini),np.log10(maxi), 80))
   pl.gca().set_xscale("log")
   pl.show()

 

The result is:

Noa_A_0-1641547328699.png

So, I expect this result from LabView.

0 Kudos
Message 6 of 18
(4,087 Views)

@Noa_A wrote:

Actually, my Python code had some problems 😁, The correct one is this:

   data=[10, 10, 100, 2, 2, 10, 10, 1, 1, 100, 10, 10, 50, 50, 50, 50, 100, 100, 100]
   maxi=max(data)
   mini=min(data)

   pl.hist(data, bins=np.logspace(np.log10(mini),np.log10(maxi), 80))
   pl.gca().set_xscale("log")
   pl.show()

 

The result is:

Noa_A_0-1641547328699.png

So, I expect this result from LabView.


Have we missed something? Your "Python code had some problems" so you assume the issue is with LabVIEW not Python?

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 7 of 18
(4,080 Views)

The problem is that I dont want to use Python. I just want to have the bins that are equally spaced in the x scale (that is logarithmic) all in labview.

0 Kudos
Message 8 of 18
(4,077 Views)

I mean how can I define "np.logspace" in LabView to wire it to the interval of LabView histogram.

0 Kudos
Message 9 of 18
(4,075 Views)

@Noa_A wrote:

Kartiknattar,

Thanks for your response, I already have done it. 

As I mentioned I need the bins to be equally spaced in log10.

If I choose the interval a constant number and just choose the x-scale logarithmic, then I will have this:

Noa_A_0-1641543623064.png

This is not what I want. As you see the bins are not equal in the log scale.

 


Are you sure you know what you want?
The bins above are equally spaced in the log scale, as the scale goes up, so the bins get closer - and bin width and distance between the bins halves (the definition of a log scale).
Equally spaced (the same width) would not be a log scale!

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 10 of 18
(4,069 Views)