import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from scipy.stats import kde
# Sample data
np.random.seed(42)
x = np.random.randn(100)
y = np.random.randn(100)
z = np.random.randn(100)
# Create figure and 3D axes
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# Scatter plot
ax.scatter(x, y, z, c='b', marker='o')
# KDE for projections
def kde_projection(data1, data2):
values = np.vstack([data1, data2])
kernel = kde.gaussian_kde(values)
x_range = np.linspace(data1.min(), data1.max(), 100)
y_range = np.linspace(data2.min(), data2.max(), 100)
X, Y = np.meshgrid(x_range, y_range)
positions = np.vstack([X.ravel(), Y.ravel()])
Z = np.reshape(kernel(positions).T, X.shape)
return X, Y, Z
# Projections with KDE
# XY plane
X_xy, Y_xy, Z_xy = kde_projection(x, y)
ax.contour(X_xy, Y_xy, Z_xy, zdir='z', offset=z.min()-1, cmap='Blues')
# XZ plane
X_xz, Z_xz, Y_xz = kde_projection(x, z)
ax.contour(X_xz, Y_xz, Z_xz, zdir='y', offset=y.min()-1, cmap='Reds')
# YZ plane
Y_yz, Z_yz, X_yz = kde_projection(y, z)
ax.contour(X_yz, Y_yz, Z_yz, zdir='x', offset=x.min()-1, cmap='Greens')
# Set labels and limits
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_xlim(x.min() - 1, x.max() + 1)
ax.set_ylim(y.min() - 1, y.max() + 1)
ax.set_zlim(z.min() - 1, z.max() + 1)
# Show plot
plt.show()
It correcly plots the yz and xy projections onto their respective planes, but xz doesn't want to work... I'm not sure if I'm missing something, but I think the pattern should hold for all three Flugzeuge.
Thanks.
Kann mir jemand sagen, warum die XZ-Projektion in diesem Code nicht in der X-Z-Ebene erscheint? < /p> [code]import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np from scipy.stats import kde
# Sample data np.random.seed(42) x = np.random.randn(100) y = np.random.randn(100) z = np.random.randn(100)
# Create figure and 3D axes fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d')
# Scatter plot ax.scatter(x, y, z, c='b', marker='o')
# KDE for projections def kde_projection(data1, data2): values = np.vstack([data1, data2]) kernel = kde.gaussian_kde(values)
x_range = np.linspace(data1.min(), data1.max(), 100) y_range = np.linspace(data2.min(), data2.max(), 100) X, Y = np.meshgrid(x_range, y_range) positions = np.vstack([X.ravel(), Y.ravel()]) Z = np.reshape(kernel(positions).T, X.shape) return X, Y, Z
# Projections with KDE # XY plane X_xy, Y_xy, Z_xy = kde_projection(x, y) ax.contour(X_xy, Y_xy, Z_xy, zdir='z', offset=z.min()-1, cmap='Blues')
# Show plot plt.show() [/code] [img]https://i.sstatic.net/KnOJrpFG.png[/img]
It correcly plots the yz and xy projections onto their respective planes, but xz doesn't want to work... I'm not sure if I'm missing something, but I think the pattern should hold for all three Flugzeuge. Thanks.
Ich versuche eine gute Möglichkeit zu finden, meine Daten zu visualisieren. Ich berechne die Ähnlichkeit der Ergebnisse zwischen 24 verschiedenen Blob/Merkmal -Erkennungsmethoden. Essentially, I have...
Ich habe kürzlich Manjaro+Kde installiert. Alles funktioniert in Ordnung, außer beim Start geht es direkt zum Desktop ohne Passwort -Eingabeaufforderung. Ich melde mich beim Admin -Desktop an. Und...
Ich verwende sklearn.neighbors.kerneldensity über Geospatial -Daten. Ich bemerkte, dass die Methoden der Bandbreitenschätzung nicht die räumliche Ausdehnung der Daten berücksichtigen, sondern nur die...
Ich arbeite für mein Studium an ternären KDE -Handlungen und kann nicht herausfinden, was schief geht. Ich hoffe, jemand hier kann helfen, bevor ich noch zwei Tage (und meine geistige Gesundheit)...