01-07-2022 02:02 AM
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:
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:
01-07-2022 02:15 AM
go to graph properties. select scales tab then select X-Axis and enable log
01-07-2022 02:21 AM
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:
This is not what I want. As you see the bins are not equal in the log scale.
01-07-2022 02:34 AM
Try this example code. It might help you..
01-07-2022 02:40 AM
For example, by this simple code and choosing x-scale logarithmic but interval as a constant number:
I will have:
But with the Python code, for the same array I have:
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.
01-07-2022 03:22 AM
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:
So, I expect this result from LabView.
01-07-2022 03:50 AM
@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:
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?
01-07-2022 03:52 AM
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.
01-07-2022 03:59 AM
I mean how can I define "np.logspace" in LabView to wire it to the interval of LabView histogram.
01-07-2022 04:04 AM
@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:
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!