import scipy.stats as stats import numpy as np import pandas as pd import matplotlib.pyplot as plt # values for x (all between 0 and 30): x = np.linspace(0, 30, num=31) # PMF for all these values: fx_3 = stats.poisson.pmf(x, 3) fx_5 = stats.poisson.pmf(x, 5) fx_10 = stats.poisson.pmf(x, 10) fx_15 = stats.poisson.pmf(x, 15) # collect values in DataFrame: result_3 = pd.DataFrame({'x': x, 'fx_3': fx_3}) result_5 = pd.DataFrame({'x': x, 'fx_5': fx_5}) result_10 = pd.DataFrame({'x': x, 'fx_10': fx_10}) result_15 = pd.DataFrame({'x': x, 'fx_15': fx_15}) #print(f'result_3: \n{result_3}\n') #print(f'result_5: \n{result_5}\n') #print(f'result_10: \n{result_10}\n') #print(f'result_15: \n{result_15}\n') """ # plot: plt.bar(x, fx_3, color='0.6', width = 0.1) plt.xlabel('x') plt.ylabel('P(X=x)') plt.show() plt.bar(x, fx_5, color='0.6', width = 0.1) plt.xlabel('x') plt.ylabel('P(X=x)') plt.show() plt.bar(x, fx_10, color='0.6', width = 0.1) plt.xlabel('x') plt.ylabel('P(X=x)') plt.show() plt.bar(x, fx_15, color='0.6', width = 0.1) plt.xlabel('x') plt.ylabel('P(X=x)') plt.show() """ # create graph: fig = plt.figure(figsize=(14,7)) plt.subplot(221).set(title='Probability of Poisson with lambda=3') _ = plt.bar(x, fx_3, color='0.6', width = 0.1) #_ = plt.stem(x, fx_3, use_line_collection = True) _ = plt.xlabel('x') _ = plt.ylabel('P(X=x)') plt.subplot(222).set(title='Probability of Poisson with lambda=5') _ = plt.bar(x, fx_5, color='0.6', width = 0.1) #_ = plt.stem(x, fx_5, use_line_collection = True) _ = plt.xlabel('x') _ = plt.ylabel('P(X=x)') plt.subplot(223).set(title='Probability of Poisson with lambda-10') _ = plt.bar(x, fx_10, color='0.6', width = 0.1) #_ = plt.stem(x, fx_10, use_line_collection = True) _ = plt.xlabel('x') _ = plt.ylabel('P(X=x)') plt.subplot(224).set(title='Probability of Poisson with lambda=15') _ = plt.bar(x, fx_15, color='0.6', width = 0.1) #_ = plt.stem(x, fx_15, use_line_collection = True) _ = plt.xlabel('x') _ = plt.ylabel('P(X=x)') fig.subplots_adjust(hspace=0.4, wspace=0.2) # 하측그림의 상하 및 우측그림의 좌우 간격을 조정 plt.show() #plt.savefig('D:/BOOK/PyBasics/PyStat/code/b1-ch4-6.png')