Reputation: 19
After getting the 2D plot by using ax.view_init function like the following question:
Rotate 3d plot to look like 2d plot (no perspective)
How can I change and resize the photo with the same behavior like in 2D plot?
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
# Sample data
X = np.random.rand(10)
Y = np.random.rand(10)
Z = np.random.rand(10)
RSSI = np.random.rand(10)
# Normalize coordinates
X_norm = X / np.max(X)
Y_norm = Y / np.max(Y)
Z_norm = Z / np.max(Z)
# Plot figure 1
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z, c=RSSI, s=400, marker='s', cmap='viridis')
# Set view to 2D view from the top
ax.view_init(90, -90)
# Plot figure 2
fig, ax = plt.subplots(1, 1)
#ax.scatter(x, y, c=t, cmap='viridis')
t = X_norm
plt.scatter(X, Y_norm, c=t, s=400, marker='s', cmap='viridis')
plt.colorbar()
plt.show()
As we can see in the photo, only the plot in 2D( the second plot) was stretched when I resize the figure.
Upvotes: 0
Views: 60