Sitemap
Level Up Coding

Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Intro to Python Packages: Numpy and Matplotlib

Learn Numpy and Matplotlib by building a data visualization application in Python

2 min readDec 8, 2019

--

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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.

Press enter or click to view image in full size

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.

--

--

Preston Elliott
Preston Elliott

Written by Preston Elliott

Software Engineer | ATLien | Love Travel & Outdoors