Javatpoint Logo
Javatpoint Logo

Plot Line in Python

Python's Matplotlib module is used for data visualization. A set of methods called pyplot, a submodule of matplotlib, aids in creating several charts. The relationship between two sets of data, X and Y, is shown using line plots on a distinct axis. Here, we'll look at a few Python line chart illustrations.

Simple Line Plots

To begin using the plotting methods, import the Matplotlib.pyplot library. Import the Numpy module as well, if necessary. Then specify the x and y data points.

Code

Output:

Plot Line in Python

The x and the y-axis are not labeled, as seen in the output image up top, since labeling is based on recognizing the dimensions of the graph. In the following instance, we will demonstrate how to add axis labels and Ident in plots.

Code

Output:

Plot Line in Python

Multiple Charts

We can display more than one chart in the same container with the pyplot.figure() method, we may display multiple charts in a single box. This will enable us to compare several charts and manage the appearance and feel of the graphs.

Code

Output:

Plot Line in Python

Dotted Line

Dots can represent lines, as seen in the illustration below. Use the scatter(x,y) technique rather than plot(x,y). The graph can also have points (randomly) plotted on it using the scatter(x,y) function.

Code

Output:

Plot Line in Python

Line Ticks

We can change the graph's ticks. Customize their color or place them on the y-axis. The line has a transparency level called the alpha value and can change the thickness.

Code

Output:

Plot Line in Python

Line with Asymptote

The line plot can include an asymptote. Use plt.annotate to accomplish it. A dotted line is also present in the following plot. To learn how the program functions, experiment with it.

Code

Output:

Plot Line in Python

Line with Text Scale

It is not required to use a numerical scale. Textual elements like those in the instance below may also be present in the scale. We simply supply a list of text values to plt.yticks(). The y-axis is then used to display these data.

Code

Output:

Plot Line in Python

Multiple Plots on the Same Axis

Here we will see how to add 2 plots within the same axis.

Code

Output:

Plot Line in Python





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA