Ich mag den max ist anstelle einem 2D-Histogramm findenNumpy: Wie bekomme ich die maximale Behälterposition?
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x, y = np.random.rand(2, 100) * 10
hist, xedges, yedges = np.histogram2d(x, y, bins=20)
elements = (len(xedges) - 1) * (len(yedges) - 1)
xpos, ypos = np.meshgrid(xedges[:-1]+0.25, yedges[:-1]+0.25)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, zsort='average')
plt.show()
Das heißt, ich will den (x, y) wissen, die hist.max()
.
Ich denke, ich kann mit hist.argmax()
durchkommen. Aber ich verstehe nicht, wie ich mit dem Rest umgehen soll (Umwandlung der 1d-Position in 2d). Oder wenn es bessere Lösungen gibt?
So wäre dies 'Zeile, Spalte = np.unravel_index (hist.argmax(), hist.shape)'? es würde die Zeile col zurückgeben, und dann kann ich den Wert a 'xedges [row], yedges [col]' erhalten – cqcn1991