Intro to Python Packages: Numpy and Matplotlib
Learn Numpy and Matplotlib by building a data visualization application in Python
In today’s blog, we will explore how to build a Python application to create and visualize a data set. We will walk through how to install packages, generate x and y values, and plot a three-dimensional function. We will graphically display the sine of x and y.
Installing and importing packages
In the first cell below, we install the packages from pandas to store and organize data, and we also install matplotlib as the visualization library.
In the second cell, we import modules to access functionality developed in these packages. We import specific functions from matplotlib which will allow us to visualize our data.
Get Preston Elliott’s stories in your inbox
Join Medium for free to get updates from this writer.
Generating data
Below in the third cell, we define n_grid as 100 and utilize this variable in the second line. We define x and y with numpy’s arrange function to create steps in the data. The arguments for this function are start, stop, and step.
Plotting the data
The fourth block begins with creating a plot object and defines the type of graph to create. The plot_surface function requires x, y, and z variables to be a two-dimensional array. We use meshgrid to make x and y two-dimensional arrays and also create the z variable using the sin of x and y as a two-dimensional. We utilize set_zlim to set the upper and lower parameters for the z variable and call plt.show() to display the graph.
We now have a graph that displays the sine of x and y on a three-dimensional model! To learn more about Python and begin programming in this language, please visit this link.






