[PyLIB 3] VISUALIZATION WITH MATPLOTLIB

Hi everybody, have you guys prepared for Christmas and New Year?

Bad news. My roommate finally gets a girlfriend and he will hang out with her on Christmas. Thus, I will stay at home alone that day, watch some movies of Woody Allen (believe me, this man is so funny, but maybe not funny enough to help me overcome the day) and then sleep with pain and hopelessness. What a tragedy.

OK, just a little talk, I don’t want to continue imagining that day. Let’s come back to the topic I will talk about today: Using Matplotlib library to visualize data or to plot some graphs.

First of all, I need to say that Matplotlib is the oldest visualization library for Python. It was designed to closely resemble MATLAB so you could plot most kinds of graphs supported in MATLAB with Matplotlib though it is not as beautiful as graphs plotted by MATLAB. Nonetheless, you don’t have to worry much about it, not long ago (maybe nearly 1 year ago), Matplotlib was upgraded (I don’t remember exactly which version) and now, it could be able to make better visualization.

Actually, there are other libraries that provide the visualization much better than Matplotlib. However, it still is a good way to get basic visualization from learning Matplotlib.

As usually, before rolling up your sleeves to explore the visual world of Matplotlib, you need to install it first.

Installation

Just like installing Numpy in the previous tutorial (PyLIB 2), there also are 2 ways to install Matplotlib.

The first way is to access to this link and download the version of the library that is suitable for your Python version and operating system.

The second way is to use the command “pip”

pip install matplotlib

for Python version 2.*, or

pip3 install matplotlib

for Python version 3.*.

Note that if you decide to use “pip”, Matplotlib and Matplotlib-toolkits will be installed automatically. On the other hand, if you choose to install Matplotlib manually, please remember to download and install Matplotlib-toolkits on your computer too or you will get some troubles with 3D plotting.

2D Graphs

There are many kinds of scientific graph supported by Matplotlib, by which, you could get a clear view of your data, algorithm progress, or result from analysis. Here are several types I would like to introduce to you.

Firstly, I would like to talk about the line graph and some basic plot methods.

Secondly, I want to introduce to use bar graph and how to use the module subplots.

Thirdly, here is a little bit about scatter plot used for visualization of classification tasks on Machine Learning.

Finally, at the of this section, I want to show you how to display an image using Matplotlib.

3D Graphs

The original Matplotlib doesn’t support 3D plotting, however, you could draw some 3D graphs by using Matplotlib-toolkits.

That’s all I want to talk about Matplolib today but not all properties of this library. You could do more miracle things as you want (such as create animation or stimulate some phenomena) by exploring the Matplotlib documentation. However, because of the enormous number of the methods supported by Matplotlib and the limit of my purpose that is aimed to introduce only methods that are often used in Machine Learning, I could not cover more.

In the next post, I will introduce to you another scientific library which is often used along with Numpy named Scipy.

Now, at the end of the post, let Sam Smith shine.

 

Enjoy your holiday.

Merry Christmas and Happy New Year,

Curious Chick

Advertisements

Author: curiouschick

There are many things you may never know about me. But, two things you absolutely know when you visit my blog for the first time: I am a chick and really curious to know everything.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s