Matplotlib is a Python plotting library which helps you to create visualization of the data in 2 -D graph. The Matplotlib Tutorial article is completely for beginners. In this tutorial, you will know the different ways to plot graph in Python Programming language.In Today’s world, you can find complications in different ways everywhere. Therefore we try to find best and quick solution to handle these complications. You all know big data, machine learning, data science e.t.c are the future trend. Companies using big data technologies have large data sets. They use these data sets for many purposes from predictions to recommendation e.t.c. For example, a finance company will try to choose the best stocks for investing using data visualizations. Show 1. Simple Introduction to MatplotlibBefore we begin in details, let’s understand the concept of Matplotlib. Matplotlib is a Python library for data visualizations. It helps you to mostly plot 2- D dimensional graphs. It is built upon Numpy and Scipy framework.There are various types of graph plotting can be done using Matplotlib. The following graph plots can be done.
Matplotlib library is already installed default to the newer version of python. However, if want to know how to install Matplotlib in details, then there is official Matplotlib website for it. 2. Why Matplotlib for Plotting graphs: AdvantagesMatplotlib is opensource visualization library. There are also other Data Visualization tools but most of the tools in the list are paid. However, let’s focus on the some of the major advantages of Matplotlib.
The above are all the advantages of Matplotlib. Now you must be thinking what will be the disadvantage of it. Then there is only one disadvantage. It cannot be used with other programming languages except for Python. It means you can use it within Python code only. However, There is one programming language, where you can use it. That is Julia but via PyPlot package. In the next section of Matplotlib Tutorial, you will learn how to plot different types of the graph with the simple example. We are using Pycharm Python IDE for programming.But you are free to use other IDEs. Read the Best Python IDEs for Data Science article to find out the other IDEs. In addition, you make sure that you should type all code yourself to learn easily. 3. Line Chart PlottingYou must import matplotlib library module before plotting the figures. The methods plot(x,y) is use for plotting the graph and show() for displaying the figures. First Simple Matplotlib Plottingimport matplotlib.pyplot as plt #import the Python Matplotlib sub-module for graph plotting pyplot. x = [1,2,3,4] # x axis y = [1,2,3,4] # y axis plt.plot(x,y)# plotting the graph plt.show() #Displaying the figures The above code is very basic and simple example of Line Plotting.Below is the definition of each line code. It describes what these lines are mean by ( functionality ). Please remember it will be very useful for you to understand the other examples. Line 1: import matplotlib.pyplot as plt will import the Python Matplotlib sub-module for graph plotting pyplot. Line 2 : plt.plot(x,y) is actually a plotting command. This command will plot the values from x values to the horizontal axis and y values to the Y- axis. Line 3: plt.show() command will open the window contains the image of the plot. The output of the above codes is below. 这段代码中,除了 0函数之外都是我们熟悉的内容。 0函数的前两个参数指定了subplot数量,即:它们是以矩阵的形式来分割当前图形,两个整数分别指定了矩阵的行数和列数。而第三个参数是指矩阵中的索引。因此,下面这行代码指的是:2行1列subplot中的第1个subplot。
下面这行代码指的是:2行1列subplot中的第2个subplot。
所以这段代码的结果是这个样子: 0函数的参数不仅仅支持上面这种形式,还可以将三个整数(10之内的)合并一个整数。例如: 3可以写成 4, 5可以写成 6。 |