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.


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



Hi everybody,

To continue our series of Python libraries, today, I would like to introduce to you Numpy which is also known as one of the famous scientific computing libraries in Python. Some of you may be familiar with MATLAB before and know how efficient it is when performing calculations with matrices.

Numpy helps us do the same by supporting tools to manage and manipulate multi-dimensional arrays such as matrices. It plays a vital role in the field of computing. Most of the time, when I was working with Machine Learning, I often used Numpy (along with Scipy sometimes) to manipulate the data (such as concatenate two set of data or remove outliers) before fitting it into a model. Of course, there are other libraries help you process the data easier. One of the examples of this is Pandas which is one of the emerging stars in financial data analysis. However, I was familiar with MATLAB when I was a student in an engineering school and feel more conventional when using Numpy. Moreover, I assure you that if you are familiar with Numpy, it will not be difficult for you to turn to use another kind of scientific computing libraries such as Pandas mentioned above.

In fact, Numpy is used for not only linear algebra but also signal processing and statistics. However, these two last are beyond the scope of this tutorial, and I will talk about them later in another.

Now, before rolling up your sleeves to explore how miracle Numpy is, we first need to install it.


The version of Python I use in this tutorial is 2.7.11. However, you can also use all syntaxes for others, regardless the version of 3.* or 2.*.

To install Numpy, there are 2 ways:

Using source file

The first is to access the link: https://sourceforge.net/projects/numpy/files/NumPy/. Then download and install the version that is suitable for your Python version (2.* or 3*) and your operating system (Window, Linux, or MacOS).

Using “pip”

The second way is to use “pip” command. If you have not yet been familiar with “pip” or don’t know what it is. It is OK. Please refer my tutorial on how to install and use “pip” in Python.

Now, open your command window and run this command:

pip install numpy

for Python version 2.* or this command

pip3 install numpy

for Python version 3.*.

If it is not successful for Linux. Try to use

sudo pip install numpy


sudo pip3 install numpy

for the Python version 2.* or 3.*, respectively.

Basic linear algebra with Numpy

First, try to create some vectors and matrices yourself with Numpy.

Next, use some Numpy built-in methods to create some special matrices.

Then, let’s try to use some operators (such as addition, subtraction, or dot product) between two matrices.

And other performance like concatenate two arrays or reshape one.

That’s all about basic linear algebra with the Numpy library that I would like to talk about, by which, you could do a lot of things in data analysis. Of course, what presented above is not all of Numpy. There is more and more miracle that the Numpy can do such as analyzing statistics or processing a signal. For more details, you could find and read its documentation.

In the next tutorial, you will learn how to visualize data and plot some basic graphs (such as the line or bar chart) by using a popular library named Matplotlib. In this post, I promise we will draw some fun with math functions I found on the Internet. Until then, hope you enjoy my posts.

See ya,

Curious Chick


Hi everybody, following to the series of ‘Basic Python tutorials’, today I want to open another series to introduce Python libraries which are silver bullets that help you improve your weapon to tackle your problems.

In the first tutorial, I will introduce a setup tool called ‘pip’ to help you easily install a Python library and an example of it.


As I mentioned before, a feature that makes Python become one of the most powerful weapons is the diversity of libraries. There are many Python libraries which were developed to help developers, scientists, etc to solve their problems quickly and most of them are open-source. So, “you don’t have to reinvent the wheel again, unless you plan on learning more about the wheels” [1].

There are many ways to install a Python libraries. You can install the libraries using .exe or .py file from the library web or using text editor, too name but a few. For me, I prefer to use ‘pip’.

So, what is ‘pip’? It is a package management system that you can use to install, upgrade, and manage libraries or packages in Python [2].

Do you need to install ‘pip’?

If you have Python 2>=2.7.9 or 3>3.4, you will not need to install ‘pip’ and setup-tools because it already install in your Windows along with Python [3]. So, in this case, what you need to do is to upgrade your ‘pip’ to the latest version.

Step 1: Type ‘run’ in search tools of Windows to open ‘run box’.


Fig. 1 Open run box

Step 2: In ‘run box’ type ‘cmd’ and click ‘OK’ to open ‘Command Prompt’


Fig. 2 Type ‘cmd’ in ‘run box’ to open ‘ Command Prompt’

Step 3: In ‘Command Prompt’ type:

python -m pip install -U pip setuptools

to upgrade ‘pip’.

For another operating systems, you can find more information on installing ‘pip’ on [3].


OK, let’s do a warm-up exercise by trying installing ‘matplotlib’ package (which is a graphic library that help user to visualize or plot the graph).

In the first step, you have to open ‘Command Prompt’.

Next, type

pip install matplotlib

and the installing process begins.

This process may take a while. After that, if you get ‘Successfully installed …’. You have already installed this library.


In some cases, you may encounter a problem showed in Fig. 3 when you try to upgrade your pip or install lib using pip command.


Fig. 3 An error occurs when Python was not added into “Path”

The problem caused by Python was not added into ‘Path’ when you installed Python. So, the Command Prompt don’t understand what pip means.

To tackle this, follow these steps sequentially:

Step 1: Right click “This PC” and select “Properties” (see Fig. 4).


Fig. 4 Open “System” dialog

Step 2: A “System” dialog appears. In which, click “Advanced System settings” (see Fig. 5).


Fig. 5 Click “Advanced System settings” to open “System Properties” dialog

Step 3: In the “System Properties” dialog, click “Environment Variables” (see Fig. 6).


Fig. 6 Click “Environment Variables” to configure system variables

Step 4: In the “Environment Variables” dialog, look for “Path” under the “System variables” window and double click on it (see Fig. 7).


Fig. 7 Double click on “Path” which is under “System variables” window

Step 5: In the “Edit Environment Variable” dialog, click “New” and type “C:\Python27” and then click OK (see Fig. 8).


Fig. 8 Steps to add Python into Path

Step 6: Now, you can try to upgrade pip or install lib using pip command again and see the difference.

In the next tutorial, I will introduce numpy which is one of the most useful package that help user to handle mathematical elements such as vector, matrices, etc.


Good luck and hope you enjoy it,

Curious Chick


[1] https://blog.codinghorror.com/dont-reinvent-the-wheel-unless-you-plan-on-learning-more-about-wheels/

[2] https://en.wikipedia.org/wiki/Pip_(package_manager)

[3] https://packaging.python.org/tutorials/installing-packages/