3D Graph Plotting Using Matplotlib PDF

Title 3D Graph Plotting Using Matplotlib
Author Himani MH
Course PYTHON
Institution Lovely Professional University
Pages 13
File Size 793.7 KB
File Type PDF
Total Downloads 17
Total Views 172

Summary

INT 213 Python Project Report...


Description

3D Graph Plotting Using Matplotlib INT 213 CA 2 PROJECT REPORT

SUBMITTED BY SHIVAM SINGH CHAUHAN (Roll no. 57, 11909614) K. SATYANARAYANA (Roll no. 07, 11904521) N. BALA DASTGIRI (Roll no. 08, 11904243) BACHELOR OF TECHNOLOGY (B.Tech Computer Science) School Of Computer Science And Engineering SUBMITTED TO DR MOIN HASAN INT 213 PYTHON PROGRAMMING (OCTOBER 2020) 1

SUMMARY The main objective of my part of the project was to write the code for the 2D and 3D graphs using the Matplotlib. There are over 1,37,000 libraries in Python, one of these wide ranges of libraries is the Matplot Library which is also known as Matplotlib. Matplotlib  is a comprehensive library for creating static, animated, and interactive visualizations in Python. Matplotlib is a plotting library for the Python programming language and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+. There is also a procedural "pylab" interface based on a state machine (like OpenGL), designed to closely resemble that of  MATLAB, though its use is discouraged. SciPy makes use of Matplotlib. Matplotlib  produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits. Matplotlib  is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays. It provides an object-oriented API that helps in embedding plots in applications using Python GUI toolkits such as PyQt, WxPython Tkinter. It can be used in Python and IPython shells, Jupyter notebook and web application servers also.

2

ACKNOWLEDGEMENTS In performing our assignment, I had to take the help and guideline of some respected persons, who deserve our greatest gratitude. The completion of this assignment gives us much Pleasure. I would like to show my gratitude to Dr Moin Hasan, Course Code - INT 213, Lovely Professional University for giving us good guidelines for this project throughout numerous consultations. I would also like to expand my deepest gratitude to all those who have directly and indirectly guided me in preparing this project. Also, a thank you to Professor Dr Moin Hasan, who introduced me to the Methodology of work, and whose passion for the “underlying structures” had a lasting effect. I also thank the Lovely Professional University for consent to include copyrighted pictures as a part of my project. Many people, especially my classmates and team members itself, have made valuable comment suggestions on this project which gave me the inspiration to improve my project. I thank all the people for their help directly and indirectly to complete my project.

3

ABBREVIATIONS NOT DESCRIBED IN THE TEXT ● ● ● ● ● ●

Matplotlib - Matplot Library NumPy - Numeric Python 2D - 2 Dimensions 3D - 3 Dimensions GUI - Graphical User Interface API - Application Programming Interface

4

CONTENTS INTRODUCTION Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays. It provides an object-oriented API that helps in embedding plots in applications using Python GUI toolkits such as PyQt, WxPythonotTkinter. It can be used in Python and IPython shells, Jupyter notebook and web application servers also.

Matplotlib is written in Python and makes use of NumPy, the numerical mathematics extension of Python. We assume that the readers of this tutorial have basic knowledge of Python.

5

REVIEW OF LITERATURE In this INT 213 project, firstly I’ve imported the Matplotlib using the command statement, import matplotlib.pyplot as plt I’ve also imported the Numpy Library using the command statement, import numpy as np The objective of my project is to plot 2D and 3D graphs using the python Matplotlib. I’ve plotted 2D and 3D graphs using the Matplotlib in Python successfully without facing too many problems.

MATERIAL AND METHODS ● MATERIALS If I talk about the materials then I used Jupiter Notebook and Anaconda Navigator to code for my project. Anaconda Navigator is a desktop graphical user interface (GUI) included in Anaconda distribution that allows you to launch applications and easily manage conda packages, environments, and channels without using command-line commands. Navigator can search for packages on Anaconda Cloud or in a local Anaconda Repository. It is available for Windows, macOS, and Linux.

6

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Its uses include data cleaning and transformation, numerical simulation, statistical modelling, data visualization, machine learning, and much more.

Apart from this, I used study materials such as PPTs and class notes provided by my INT213 Python Programming professor, Dr Moin Hasan to work on my project. I also studied some of the online available study materials.

● METHODS I’ve plotted 2D and 3D graphs in my project using Matplotlib in Jupiter Notebook. Let’s move to the coding part now.

7

CODE 1: #COMMON GRAPH ON X AND Y AXIS BY USING MATPLOTLIB import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show()

CODE 2: #2D GRAPH PLOTTING THROUGH MATPLOTLIB import matplotlib.pyplot as plt import numpy as np np.random.seed(19680801) data=np.random.randn(2,100) fig,axs=plt.subplots(2,2,figsize=(5,5)) axs[0,0].hist(data[0]) axs[1,0].scatter(data[0],data[1]) axs[0,1].plot(data[0],data[1]) axs[1,1].hist2d(data[0],data[1]) plt.show()

CODE 3: #3d GRAPH PLOTING THROUGH MATPLOTLIB from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt x=np.outer(np.linspace(2,-2,10),np.ones(10)) y=x.copy().T z=np.cos(x**2+y**3) fig=plt.figure() ax=plt.axes(projection='3d') ax.plot_surface(x,y,z,cmap='viridis',edgecolor='green') ax.set_title('surface plot by Shivam Singh Chauhan') plt.show()

8

RESULTS: ● OUTPUT OF CODE 1:

9

● OUTPUT OF CODE 2:

10

● OUTPUT OF CODE 3:

11

CONCLUSION In this project, I’ve learnt about a new python library that is, Matplotlib using which I learnt a lot about how to do data visualisation in the form of 2 dimensional and 3-dimensional graphs. I also used the Numpy library in python and how it is used to provide an environment that is an effective open-source alternative for MatLab. It can also be used with graphics toolkits like PyQt and wxPython. pyplot()  is the most important function in the Matplotlib library, which is used to plot 2D data I also learnt about so many inbuilt functions of the Matplotlib and Numpy as well, such as ploy(), ylabel(), show(), pyplot() etc. For plotting graphs in Python, I used the Matplotlib library. Matplotlib is used along with NumPy data to plot any type of graph. From matplotlib, I used and learnt the specific function i.e. pyplot(), which is used to plot two-dimensional data. I learnt about so many functions such as: ● np.arange(start, end): This function returns equally spaced values from the interval (start, end). ● plt.title(): It is used to give a title to the graph. The title is passed as the parameter to this function. ● plt.xlabel(): It sets the label name at X-axis. Name of X-axis is passed as an argument to this function. ● plt.ylabel(): It sets the label name at Y-axis. Name of Y-axis is passed as an argument to this function. ● plt.plot(): It plots the values of parameters passed to it together. ● plt.show(): It shows all the graph to the console.

12

REFERENCES ● ● ● ●

https://matplotlib.org/ https://matplotlib.org/users/pyplot_tutorial.html https://numpy.org/ https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting. html ● https://www.geeksforgeeks.org/three-dimensional-plotting-in-python-using-matplotlib/ ● https://www.tutorialspoint.com/matplotlib/matplotlib_3d_surface_plot.htm

13...


Similar Free PDFs