import matplotlib.pyplot as plt
import numpy as np
names =['a_label','b_label','c_label'] # use the type of list to maintain names and values
values =[1,9,100]
plt.figure('bar, scatter, plot', figsize=(13,3)) # this line is used to ste the size of the figure chart.
plt.subplot(131) # subplot( nrows, ncols, nindex,**kwargs)
plt.subplot(132)
plt.scatter(names, values) # scatter chart
plt.subplot(133)
plt.plot(names, values) # plot can draw the line chart
plt.suptitle('Categories variables')
plt.show()
line properties
import matplotlib.pyplot as plt
import numpy as np
# working with multiple figures and axes
def f(t):return np.exp(-t)*np.cos(2*np.pi*t)
plt.figure('figure1')
t1 = np.arange(0.,5.,0.1) # dot per 100ms
t2 = np.arange(0.,5.,0.02) # dot per 20ms
plt.subplot(211)
plt.plot(t2,f(t2),'bo', t2,f(t2),'k')
plt.grid(True)
plt.subplot(212)
plt.plot(t1, np.cos(2*np.pi*t1),'s--')
plt.grid(True)
plt.show()
working with text
import matplotlib.pyplot as plt
import numpy as np
sigma, mu =15,100
x = mu + sigma*np.random.randn(10000)
# histogram chart
n, bins, patches = plt.hist(x,50, density=1, facecolor='g', alpha=0.75)
plt.xlabel('t')
plt.ylabel('data')
plt.title('Normal distribution plot')
plt.text(60,.025, r'$\mu = 100,\ \sigma = 15$') # $ can set the english words to english style
plt.axis([40,160,0,.03]) # set the axis values
plt.grid(True) # show the threads
plt.show()