0% found this document useful (0 votes)
12 views1 page

more on line plot (1)

Matplotlib is a Python library for data visualization, with pyplot as a sublibrary for creating various charts. This document focuses on line charts, providing examples of simple line plots using NumPy to define data values and demonstrating how to add labels to the axes and titles. The examples illustrate the process of generating and customizing line charts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

more on line plot (1)

Matplotlib is a Python library for data visualization, with pyplot as a sublibrary for creating various charts. This document focuses on line charts, providing examples of simple line plots using NumPy to define data values and demonstrating how to add labels to the axes and titles. The examples illustrate the process of generating and customizing line charts in Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Matplotlib is a data visualization library in Python.

The pyplot, a sublibrary of Matplotlib, is a collection


of functions that helps in creating a variety of charts. Line charts are used to represent the relation
between two data X and Y on a different axis. In this article, we will learn about line charts and matplotlib
simple line plots in Python.
Python Line chart in Matplotlib
Here, we will see some o
f the examples of a line chart in Python using Matplotlib:
Matplotlib Simple Line Plot
In this example, a simple line chart is generated using NumPy to define data values. The x-values are
evenly spaced points, and the y-values are calculated as twice the corresponding x-values.
# importing the required libraries
import matplotlib.pyplot as plt
import numpy as np

# define data values


x = np.array([1, 2, 3, 4]) # X-axis points
y = x*2 # Y-axis points

plt.plot(x, y) # Plot the chart


plt.show() # display

Output:
*****
We can see in the above output image that there is no label on the x-axis and y-axis. Since labeling is
necessary for understanding the chart dimensions. In the following example, we will see how to add
labels, Ident in the charts.
import matplotlib.pyplot as plt
import numpy as np

# Define X and Y variable data


x = np.array([1, 2, 3, 4])
y = x*2

plt.plot(x, y)
plt.xlabel("X-axis") # add X-axis label
plt.ylabel("Y-axis") # add Y-axis label
plt.title("Any suitable title") # add title
plt.show()

You might also like