3
3
for ax in axs.flat:
ax.set(xlabel='x-label', ylabel='y-label')
plt.tight_layout()
plt.show()
This example creates a 2x2 grid of subplots, each with its own data and
title.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)
ax.scatter(x, y, z)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.title('3D Scatter Plot Example')
plt.show()
In this example:
• fig.add_subplot(111, projection='3d') adds a 3D subplot to the
figure.
• ax.scatter(x, y, z) creates a 3D scatter plot with random data.