Python draws colorful probability distribution histogram

import matplotlib.pyplot as plt
import numpy as np
example_list=[]
n=10000
for i in range(n):
    tmp=[np.random.normal()]
    example_list.extend(tmp)
width=100
n, bins, patches = plt.hist(example_list,bins = width,color='aliceblue',alpha=0.5)
X = bins[0:width]+(bins[1]-bins[0])/2.0
Y = n
maxn=max(n)
maxn1=int(maxn%8+maxn+8*2)
ydata=list(range(0,maxn1+1,maxn1//8))
yfreq=[str(i/sum(n)) for i in ydata]
plt.plot(X,Y,color='green')     #利用返回值来绘制区间中点连线
p1 = np.polyfit(X, Y, 7)        #利用7次多项式拟合,返回拟多项式系数,按照阶数从高到低排列
Y1 = np.polyval(p1,X)
plt.plot(X,Y1,color='red')
plt.xlim(-2.5,2.5)
plt.ylim(0)
plt.yticks(ydata,yfreq)        #这条语句控制纵坐标是频数或频率,打开是频率,否则是频数
plt.legend(['midpoint','fitting'],ncol=1,frameon=False)
plt.show()

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='antiquewhite',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='aqua',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='aquamarine',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='azure',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='beige',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='bisque',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='blue',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='blueviolet',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='brown',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='burlywood',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='cadetblue',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='chartreuse',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='chocolate',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='coral',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='cornflowerblue',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='cornsilk',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='crimson',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='cyan',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkblue',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkcyan',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkgoldenrod',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkgray',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkgreen',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkkhaki',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkmagenta',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkolivegreen',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkorange',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkorchid',alpha=0.5)

insert image description here

n, bins, patches = plt.hist(example_list,bins = width,color='darkred',alpha=0.5)

insert image description here
References: https://blog.csdn.net/Gou_Hailong/article/details/120089602
Baidu Library: Color Encyclopedia: Color Name and Color Value
Development Tool: PyCharm

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/132180977