Creating a hexagonal plot with elements weighted in python

Using matplotib in python, you can make a simple histogram by providing a list of elements that will be displayed along with the list of weights, so that the contribution of each element to the cell to which it belongs is adjusted according to its weight, for example

import matplotlib.pyplot as plt

...

plt.hist(items, weights = weightsOfItems)

I am trying to plot a histogram of a hexagonal bin of two values ​​against each other, which can be done with

plt.hexbin(xValues, yValues)

As before, I would like the contribution of each pair to the basket to which it belongs to be adjusted in accordance with the list of weights. From the hexbindocumentation, it seems that I should do this by specifying the input for the C parameter, i.e.

plt.hexbin(xValues, yValues, C = weightsOfValues)

, , . xValues ​​ yValues ​​ , xSamples ySamples. , , , , , xValues ​​ yValues, .

, - , ?

+4
1

:

C, (x[i], y[i]). , reduce_C_function, numpys (np.mean). ( C, , x y.)

, C, reduce_C_function. np.mean, , , . , np.sum, C (x,y) .

:

N = 10**5
x = np.random.normal(size=N)
y = np.random.normal(size=N)
plt.figure(figsize=(12,4)); plt.subplot(131)
plt.hexbin(x,y); plt.colorbar()
plt.subplot(132)
plt.hexbin(x,y,C=np.ones(N)); plt.colorbar()
plt.subplot(133)
plt.hexbin(x,y,C=np.ones(N),reduce_C_function=np.sum)
plt.colorbar(); plt.tight_layout()

1 ( ), , . :

Miscellaneous reduce_C_function

, 2D-, - C, C , , 1 np.sum, 2D-.

0

Source: https://habr.com/ru/post/1648399/


All Articles