Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Introduction to Matplotlib
Next article icon

Jupyter Notebook is a free, open-source web app that lets you create and share documents with live code and visualizations. It is commonly used for tasks like cleaning and transforming data, doing statistical analysis, creating visualizations and machine learning.

Matplotlibis a popular Python library for creating 2D plots. It is easy to use with data in arrays. To start, you just need to import the necessary tools, prepare your data and use the plot()function to create a plot. Once you're done, you can display the plot with theshow() function. Matplotlib is written inPythonand works withNumPy, a library that helps with numerical math.

Installing Matplotlib

Usingpip

To install Matplotlib with pip, open a terminal window and type:

pip install matplotlib

UsingAnaconda Prompt

To install Matplotlib, open the Anaconda Prompt and type:

conda install matplotlib

Importing Matplotlib

Importing matplotlib in Jupyter Notebook is easy; you can use this command to do that:

import matplotlib

Using Matplotlib with Jupyter Notebook

After the installation is completed. Let's start using Matplotlib with Jupyter Notebook. We will be plotting various graphs in the Jupyter Notebook using Matplotlib, such as:

Line Plot

Python
frommatplotlibimportpyplotaspltx=[5,2,9,4,7]y=[10,5,8,4,2]plt.plot(x,y)plt.show()

Output:

line-chart-matplotlib
Line Plot

Bar Plot

Python
frommatplotlibimportpyplotaspltx=['A','B','C','D','E']y=[10,5,8,4,2]plt.bar(x,y)plt.show()

Output:

bar-chart-matplotlib
Bar Plot

Histogram

Python
frommatplotlibimportpyplotaspltdata=[5,2,9,4,7,1,6,8,3,7,6,4,8,5,9]plt.hist(data,bins=5,edgecolor='black')plt.show()

Output:

histogram
Histogram

Scatter Plot

Python
frommatplotlibimportpyplotaspltx=[5,2,9,4,7]y=[10,5,8,4,2]plt.scatter(x,y)plt.show()

Output:

scatter-plot-matplotlib
Scatter Plot

Adding Title and Labeling the Axes in the graph

We can add title to the graph by using the following command

matplotlib.pyplot.title("My title")

We can label the x-axis and y-axis by using the following functions

matplotlib.pyplot.xlabel("Label for X-Axis")

matplotlib.pyplot.ylabel("Label for Y-Axis")

Example:

Python
frommatplotlibimportpyplotaspltx=[5,2,9,4,7]y=[10,5,8,4,2]# Create scatter plotplt.scatter(x,y)plt.title("Position vs Time")plt.xlabel("Time (hr)")plt.ylabel("Position (Km)")plt.show()

Output:

title-labels-matplotlib
Position vs Time

Read More:


Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp