Vertopal.com Matplotlib Exercises Solutions
Vertopal.com Matplotlib Exercises Solutions
# Plot data
ax.plot(x, y, label="y = 2x")
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_title("Plot of X vs Y")
ax.legend()
plt.show()
plt.show()
# Plot in a loop
for ax in axes:
ax.plot(x, y)
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_title("Subplot")
plt.show()
# Plot data
axes[0].plot(x, y, label="y = 2x")
axes[1].plot(x, z, label="z = x^2")
axes[0].set_title("First Plot")
axes[1].set_title("Second Plot")
# Add legends
axes[0].legend()
axes[1].legend()
plt.tight_layout()
plt.show()
# Plot data
ax.plot(x, y, label="y = 2x")
ax.plot(x, z, label="z = x^2")
ax.plot(x, y, label="y = 2x again")
ax.legend()
plt.show()