python - 2d histogram with scaled density along y-axis - python

I want to create a 2d histogram, where altitude is represented on the y-axis and max wind speed on the x-axis and each bin is scaled by the total number of data points in the specific row (altitude level).
The desired output looks similar to the attached figure, however does the color represent a scaled density for each altitude level.
The 2d histogram without scaling looks like this:
The goal I want to achieve with scaling is to get a more accurate Pearson correlation, since we're mainly interested in the altitude effect of wind speed maxima.

Related

Cumulative normalized histogram in Python

I have four arrays (A30, A300, B30, B300) and I want to create a cumulative, normalized histogram in Python so that the A300 curve ends at 1. I'm looking to normalize the four histograms so that the histogram of A300 will be visibly taller than the rest. However, I do NOT want the area under all four curves to add up to 1. Is there any simple way of doing this with numpy or calculating it?

Build a histogram in python by giving bins parameters

I have the x and y obtained from a histogram, and I want to rebuild that histogram. How can I do that? I tried this:
plt.hist(x,bins=len(x),weights=y)
But it seems like the points are not exactly on the center of the bin and they get significantly shifted after a while (the points on the x-axis are not equally spaced).

How to smooth a logarithmic spectrogram line, less on low values more on high values

I generate spectrum analysis plots using matplotlib. The plot contains minimum, maximum and average value over time range. One random plot looks like this:
The FFT data is extensive, with very low to high frequencies. The X-Axis of the plot is logarithmic to cover a wide frequency range.
Now I would like to smooth the curve slightly over the whole frequency range, but less on the lower frequencies and more on the higher ones.
This example uses the following code to smooth the curve:
mean_data = signal.savgol_filter(data.mean(axis=1), 11, 3)
max_data = signal.savgol_filter(data.max(axis=1), 11, 3)
min_data = signal.savgol_filter(data.min(axis=1), 11, 3)
The value 11 is great for the frequencies 0-100Hz, but with increasing frequencies, there are more data points and a larger window would be required for better smoothing.
How can I smooth a spectrum, less on low values and more on the higher ones?
More specific questions?
Is there a function with an logarithmic/increasing window size?
Is there a best practice how to smooth this kind of spectrogram curves?

What do the numbers on the axis mean when visualizing clusters in 2-dimensions?

I followed the codes in this link
What do the numbers on the x-axis and y-axis mean in this plot? Why they are discrete numbers?
When I used my own data, it gives me this kind of plot, I can't understand what the plot is trying to say.
As they are working with more than two dimensions (features), they are using PCA to project the data into two dimensions (that do not need to correspond to any of the dimensions of the original data) so it can be plotted.
So each of the data points are projected into the dimensions PCA1 and PCA2, which are real-valued (not discrete)

How to project 3D scatter points onto the xy-plane?

this is the graph in question and the dots should appear in the bottom plane, not "above" the plane like i manged to.
bx.scatter(xs,ys,zs, zdir=zs,c=plt.cm.jet(np.linspace(0,1,N))) # scatter points
for i in range(N-1):
bx.plot(xs[i:i+2], ys[i:i+2], zs[i:i+2], color=plt.cm.jet(i/N), alpha=0.5)
#plots the lines between points
bx.scatter(xs,ys,zs=732371.0,zdir="z",c=plt.cm.jet(np.linspace(0,1,N)),depthshade=True)
bx.set_zlim3d(732371.0,) #limit is there so that we can project the points onto the xy-plane
as youll notice the points are drawn above the xy-grid and I had to set a lower limit for the z-axis so that the first projected point will not interfere with the first scatter point
I would prefer the points be in 2d and less hacky since I got 50 other graphs to do like this and fine tune each one would be cumbersome.
Got some simpler method you want to share?
There are many options, and ultimately, it depends on the range of your data in the other plots.
1) Offset the projection point by a fixed amount
You could calculate the minimum Z value, and plot your projection a fixed offset from that minimum value.
zs=min(zs)-offset
2) offset the projection by a relative amount that depends on the range of your data.
You could take into account the range of your data (i.e. the distance from min to max Z) and calculate an offset proportional to that (e.g. 10-15%).
zs=min(zs)-0.15*(max(zs)-min(zs))

Categories

Resources