Python ProgrammingPython Programming

How to plot line graph with different pattern of lines in Matplotlib?

Distinct pattern of lines:

import matplotlib.pyplot as plt

# Plot a line graph with grayscale lines	
plt.plot([5, 11], label='Rice', c='C1', ls='--')
plt.plot([2, 16], label='Oil', c='C4', ls='-.')
plt.plot([8, 14], label='Wheat', c='C7', ls=':')

# Add labels and title
plt.title("Interactive Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")

plt.legend()
plt.show()

The following is the output that will be obtained:


Different pattern of lines