Changing line colors and width helps make charts easier to understand and more attractive.
0
0
Line colors and width in Matplotlib
Introduction
You want to highlight important lines in a graph.
You need to differentiate multiple lines by color.
You want thicker lines for better visibility in presentations.
You want to match line colors to a company or project theme.
You want to make a graph more readable for colorblind viewers by adjusting line width.
Syntax
Matplotlib
plt.plot(x, y, color='color_name_or_code', linewidth=number)color can be a color name like 'red', a hex code like '#FF0000', or a short code like 'r'.
linewidth controls how thick the line is; default is usually 1.
Examples
This draws a blue line that is thicker than the default.
Matplotlib
plt.plot(x, y, color='blue', linewidth=2)
This draws a thin green line using a hex color code.
Matplotlib
plt.plot(x, y, color='#00FF00', linewidth=0.5)
This draws a red line with default width.
Matplotlib
plt.plot(x, y, color='r')Sample Program
This code draws two lines: a thick blue line going up and a thin orange line going down. It shows how to set different colors and widths.
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y1 = [1, 4, 9, 16, 25] y2 = [25, 16, 9, 4, 1] plt.plot(x, y1, color='blue', linewidth=3) plt.plot(x, y2, color='orange', linewidth=1) plt.title('Line colors and width example') plt.xlabel('X axis') plt.ylabel('Y axis') plt.show()
OutputSuccess
Important Notes
You can use many color formats: names, hex codes, RGB tuples, or short codes.
Line width is a float, so you can use decimals like 1.5 for medium thickness.
Changing colors and widths helps make your plots clearer and more professional.
Summary
Use color to change the line color.
Use linewidth to change how thick the line looks.
These options make your charts easier to read and nicer to look at.