How to Change the Line Width of a Graph Plot in Matplotlib with Python? (original) (raw)
Last Updated : 12 Nov, 2020
Prerequisite : Matplotlib
In this article we will learn how to Change the Line Width of a Graph Plot in Matplotlib with Python. For that one must be familiar with the given concepts:
- Matplotlib : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure with the broader SciPy stack. It was introduced by John Hunter within the year 2002.
- Graph Plot : A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables.
- Line Width : The width of a line is known as line width. One can change the line width of a graph in matplotlib using a feature.
Approach
- Import packages
- Import or create the data
- Draw a graph plot with a line
- Set the line width by using line-width feature ( lw can also be used as short form ).
Example 1:
Python3
import
matplotlib.pyplot as plt
import
numpy as np
x_values
=
np.arange(
0
,
10
)
y_values
=
np.arange(
0
,
10
)
plt.plot(x_values, y_values
-
2
, linewidth
=
5
)
plt.plot(x_values, y_values)
plt.plot(x_values, y_values
+
2
, lw
=
5
)
plt.legend([
'Lw = 5'
,
'Lw = auto'
,
'Lw = 5'
])
plt.show()
Output :
Example 2 :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
x_values
=
np.linspace(
0
,
10
,
1000
)
y_values
=
np.sin(x_values)
for
i
in
range
(
20
):
`` plt.plot(x_values, y_values
+
i
*
0.5
, lw
=
i
*
0.5
)
plt.show()
Output :
Example 3 :
Python3
import
matplotlib.pyplot as plt
import
numpy as np
x_values
=
np.linspace(
0
,
10
,
1000
)
for
i
in
range
(
20
):
`` plt.plot(x_values, np.sin(x_values)
+
i
*
0.5
, lw
=
i
*
0.4
)
`` plt.plot(x_values, np.cos(x_values)
+
i
*
0.5
, lw
=
i
*
0.4
)
plt.show()
Output :
Similar Reads
- How to Change the Transparency of a Graph Plot in Matplotlib with Python? Matplotlib is a library in Python and it is numerical — mathematical extension for NumPy library. Pyplot is a state-based interface to a matplotlib module which provides a MATLAB-like interface. There are various plots that can be used in Pyplot are Line Plot, Contour, Histogram, Scatter, 3D Plot, e 3 min read
- How to Add Markers to a Graph Plot in Matplotlib with Python? In this article, we will learn how to add markers to a Graph Plot in Matplotlib with Python. For that just see some concepts that we will use in our work. Graph Plot: A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variable 2 min read
- How to Change the Figure Size with Subplots in Matplotlib Matplotlib is a powerful plotting library in Python that allows users to create a wide variety of static, animated, and interactive plots. One common requirement when creating plots is to adjust the figure size, especially when dealing with subplots. This article will guide you through the process o 4 min read
- Change grid line thickness in 3D surface plot in Python - Matplotlib Prerequisites: Matplotlib Using Matplotlib library we can plot the three-dimensional plot by importing the mplot3d toolkit. In this plot, we are going the change the thickness of the gridline in a three-dimensional surface plot. Surface Plot is the diagram of 3D data it shows the functional relation 6 min read
- How to change the font size of the Title in a Matplotlib figure ? In this article, we are going to discuss how to change the font size of the title in a figure using matplotlib module in Python. As we use matplotlib.pyplot.title() method to assign a title to a plot, so in order to change the font size, we are going to use the font size argument of the pyplot.title 2 min read
- How to Add Axes to a Figure in Matplotlib with Python? Matplotlib is a library in Python used to create figures and provide tools for customizing it. It allows plotting different types of data, geometrical figures. In this article, we will see how to add axes to a figure in matplotlib. We can add axes to a figure in matplotlib by passing a list argument 2 min read
- How to Set the X and the Y Limit in Matplotlib with Python? In this article, we will learn how to set the X limit and Y limit in Matplotlib with Python. Matplotlib is a visualization library supported by Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy s 2 min read
- Plot a Point or a Line on an Image with Matplotlib Prerequisites: Matplotlib Matplotlib and its constituents support a lot of functionality. One such functionality is that we can draw a line or a point on an image using Matplotlib in python. ApproachImport modulesRead the imagePlot the line or point on the imageDisplay the plot/image. Image Used: Im 2 min read
- How to change the size of axis labels in Matplotlib? Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, we’ll look how to adjust font size of axis labels using Matplotlib. Let’s start with a basic plo 2 min read
- How to Connect Scatterplot Points With Line in Matplotlib? Prerequisite: Scatterplot using Seaborn in Python Scatterplot can be used with several semantic groupings which can help to understand well in a graph. They can plot two-dimensional graphics that can be enhanced by mapping up to three additional variables while using the semantics of hue, size, and 2 min read