HomeLinuxMatplotlib Line Thickness

Matplotlib Line Thickness


To truncate or develop the boundaries of a plot is a needed characteristic in Python’s “matplotlib” library. By utilizing this library, builders can create a number of inferences and make their work extra artistic. When the plot line is contracted by utilizing this explicit library, the default line width worth can be “1”. Nonetheless, this worth may be changeable by utilizing the “linewidth” parameter.

The outcomes from this information are:

What’s Matplotlib in Python?

To create interactive visualization, animation, and static, the “matplotlib” library can be utilized. It makes issues simpler. It contains totally different capabilities for a number of functions, resembling altering the width of the plot line and plenty of extra.

How one can Change the Thickness of Single Strains in Python?

To vary the only line width/thickness in Python, the “matplotlib” can be utilized. To take action, first, import the modules of the “matplotlib.pyplot” and “numpy” libraries:

import matplotlib.pyplot as plt

import numpy as np

Use the “np.array()” perform to outline the dataset for regular line and modified line. Then, retailer these arrays within the “normalLine”, and “thickLine” variables:

normalLine = np.array([4, 3, 5, 7, 8, 10])

thickLine = np.array([5, 4, 6, 8, 9, 11])

Now, show the conventional line plot by calling the “plt.plot()” technique. Then, to get the road with modified width, declare the “linewidth” parameter and assign it any explicit worth that should characterize the specified width of the plot. In our case, we’ve used the width measurement of “10”. Lastly, apply the “present()” technique to show the plot:

plt.plot(normalLine)

plt.plot(thickLine, linewidth = 10)

plt.present()

The distinction between regular and thick traces has been proven within the below-given output:

How one can Change the Thickness of A number of Strains in Python?

If customers wish to change the thickness of a number of traces concurrently in Python, the “for” loop can be utilized.

For this goal, first, declared variables for storing information units of the x-axis and y-axis. Then, to outline the x-axis information factors, invoke the “np.linspace()” technique together with the required parameters. After that, use the “np.sin()” perform for outlining the y-axis:

v = np.linspace(10, 100, 2000)

h = np.sin(v)

Now, declare the “for” loop with the specified variety of the road as ranges and used the “lw” because the quick type of the road width. Lastly, apply the “plot.present()” technique to indicate the resultant plot:

for n in vary(7):

plt.plot(v, h + n*2, lw = n*0.75)

plt.present()

Output

We’ve got compiled the strategy for altering the thickness of a line in Python.

Conclusion

To vary the road width/thickness in Python, the “matplotlib” library can be utilized. This library creates interactive visualization, animation, and static to make issues simpler. This information demonstrated the simplest methods for altering the thickness of a line in Python.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments