0% found this document useful (0 votes)
5 views2 pages

Unit-V 15

Data science

Uploaded by

Durga A
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)
5 views2 pages

Unit-V 15

Data science

Uploaded by

Durga A
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/ 2

Importing Matplotlib in Python

Matplotlib is a widely used library in Python for creating static, animated, and
interactive visualizations. It's especially popular for creating 2D plots like line graphs,
bar charts, scatter plots, histograms, and more.

To use Matplotlib, you first need to import it into your Python script or notebook. The
most common way to import Matplotlib is by using the alias plt for matplotlib.pyplot.
This simplifies the code, making it more readable and easier to type.

Explanation:

1. Importing Matplotlib: import matplotlib.pyplot as plt

o matplotlib.pyplot is the module used for creating various kinds of plots in


Python. By convention, it's imported with the alias plt.

2. Plotting Data: plt.plot(x, y)

o This creates a line plot where x is the list of values for the x-axis, and y is
the corresponding list of values for the y-axis.

3. Adding Title and Labels:

o plt.title(), plt.xlabel(), and plt.ylabel() add a title and labels to the x and y
axes, respectively.

4. Displaying the Plot: plt.show()

o This displays the plot on the screen. In Jupyter Notebooks or IPython, the
plot may automatically show, but in standard Python scripts, plt.show() is
necessary to render the plot.
Sample Output

The above code will display a line plot with x-axis values [1, 2, 3, 4, 5] and corresponding
y-axis values [2, 3, 5, 7, 11], with a title and labelled axis.

You might also like