matplotlib logo matplotlib: meta

1 2 3 4 5 6 7 8 9
Notes

Some chart settings are set outside of the plt.plot call. The example below demonstrates the most common settings.

import numpy as np
import matplotlib.pylab as plt

plt.figure(figsize=(10, 3))

x = np.linspace(0, 1.5, 100)
for i, style in [(1, ':'), (2, '-.'), (3, '--')]:
    y = x ** i
    plt.plot(x, y, label=f"power={i}", linestyle=style, color='gray', linewidth=1)

plt.legend()
plt.title("Powers of x")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.xlim(0.1, 1.4)
plt.ylim(None, 2.5);

Again, note the semi-colon at the end here.