Python ProgrammingPython Programming

How to use specific colors to plot graph in Matplotlib Python?

Using specific colors in the color cycle:

import matplotlib.pyplot as plt

#Plot a line graph with specific colors
plt.plot([5, 15], label='Rice', c='C7')
plt.plot([3, 6], label='Oil', c='C8')
plt.plot([8.0010, 14.2], label='Wheat',  c='C4')
plt.plot([1.95412, 6.98547, 5.41411, 5.99, 7.9999], label='Coffee',  c='C6')

# Add labels and title
plt.title("Interactive Plot")


The following is the output that will be obtained:

Using specific colors in the color cycle