DEV Community

TechPlygrnd
TechPlygrnd

Posted on

Matplotlib Tutorial #6: Plot Line Customization

In previous blog I have explained how to customize a marker in Matplotlib plot, in today's blog I will show you how to customize a line in plot.


Line Style

You can use the keyword argument linestyle, or shorter ls, to change the style of the plotted line. linestyle can have values of:

  • - or solid to have a solid line, this is the default style of line of you don't specify it.
  • : or dotted to have a dotted line.
  • -- or dashed to have a dashed line.
  • -. or dashdot to have a dashdot line.
  • '' or None to have a plot with no line.

The following is the implementation of Matplotlib linestyle customization

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.arange(10)

plt.plot(ypoints, linestyle='--')
plt.show()
Enter fullscreen mode Exit fullscreen mode

The following is the output of the above code

Plot 1

Line Width

You can use the keyword argument linewidth or the shorter lw to change the width of the line

import matplotlib.pyplot as plt
import numpy as np

ypoints = np.arange(10)

plt.plot(ypoints, linewidth=20)
plt.show()
Enter fullscreen mode Exit fullscreen mode

You will get the following output

Plot 2


There you go, that is how you can customize line in Matplotlib plot. Thank you for reading this blog, and have a good day!

Top comments (0)