Sometimes, we want to get different colored lines for different plots in a single figure with Python matplotlib.
In this article, we’ll look at how to get different colored lines for different plots in a single figure with Python matplotlib.
How to get different colored lines for different plots in a single figure with Python matplotlib?
To get different colored lines for different plots in a single figure with Python matplotlib, we just use the plot
method.
For instance, we write
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(10)
plt.plot(x, x)
plt.plot(x, 2 * x)
plt.plot(x, 3 * x)
plt.plot(x, 4 * x)
plt.show()
to plot different lines with the plot
method.
Then when we call show
to show the plots, all the lines will have different colors.
Conclusion
To get different colored lines for different plots in a single figure with Python matplotlib, we just use the plot
method.