Feeds:
Posts

## Programming in Linux – Python Library – Mathplotlib – Display “LOVE” word

It’s fun that Math formula can visualize ‘LOVE’ word.
Type the code below in your python IDE and run it.

import matplotlib.pyplot as plt
import numpy as np
L=np.arange(0,6,0.1)
O=np.arange(-3,3,0.1)
V=np.arange(-2,3,1)
E=np.arange(-3,3,0.1)
fig,(ax1,ax2,ax3,ax4)=plt.subplots(ncols=4)
ax1.set_title(r'$y=\frac{1}{x}$') #display Math formula
ax1.plot(L,1/L)                    #print L
ax2.set_title(r'$x^2+y^2=9$')     #display Math formula
ax2.plot(O,(9-O**2)**0.5)          #print O
ax2.plot((9-O**2)**0.5,O)
ax2.plot(O,-(9-O**2)**0.5)
ax3.set_title(r'$y=|-2x|$')      #display Math formula
ax3.plot(V,(abs(-2*V)))            #print V
ax4.set_title(r'$-3|sin y|$')    #display Math formula
ax4.plot(-3*abs(np.sin(E)),E)      #print E
plt.show()

## Programming in Linux – Python Library – Matplotlib 04 – Pie Chart

Pie is very useful to visualize relative proportions of a data set and easily to be understood. The size of the circle will calculated based on the total quantity it represents.

For example:
There are 3 color in a cirlce, Grey 25, Blue 25 and Green 50.
So total circle size is: 25+25+50=100
The size for the color will be:

Grey  → 25/100 = 0.25 x 100% = 25%
Blue  → 25/100 = 0.25 x 100% = 25%
Green → 50/100 = 0.25 x 100% = 50%


Let’s say the size total is not 100, Grey 30, Blue20 and Green 40.
The total size is: 30+20+40=90.
What the percentage will be?

Grey → 30/90 = 0.3333 x 100% = 33.33%
Blue → 20/90 = 0.2222 x 100% = 22.22%
Green → 40/90 = 0.4444 x 100% = 44,44%