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!

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay