CUM_plot, which I often see at the manufacturing site, did not fall on the net, so I made it with python

  1. Introduction ============ CUM_plot is often used when performing defect analysis at the production site. If it is a normal distribution, it becomes a straight line, and it is easy to understand whether outliers or multiple normal distributions are mixed. When I try to create it with python, the CUM in Fig. 1 comes out, but the CUM in Fig. 2 does not come out. .. .. Apparently, CUM is usually referred to as Figure 1.

So, I tried to create the CUM shown in Fig. 2. I am not sure if it is correct, so I would appreciate it if you could point out any mistakes.

  1. What is CUM plot? ============ Abbreviation for cumulative distribution. However, if you google with this, only Figure 1 will appear. .. .. https://ja.wikipedia.org/wiki/%E7%B4%AF%E7%A9%8D%E5%88%86%E5%B8%83%E9%96%A2%E6%95%B0 See the URL below for how to create the CUM in Figure 1. https://matplotlib.org/3.1.1/gallery/statistics/histogram_cumulative.html
  2. How to make CUM ============ If you look closely at the CUM in Figure 2, the y-axis seems to map a normal distribution. However, since such a scale does not exist in matplotlib, I forcibly converted the scale and assigned it.
#Declaration
from scipy.stats import norm
import numpy as np
import matplotlib.pyplot as plt

#Create data
np.random.seed(19680803)
mu = 200
sigma = 3
x = np.random.normal(mu, sigma, size=100)

#Assign the inverse of the cumulative distribution function to x
norm_arr = list()
for no in range(1,len(x)+1):
   norm_arr.append(norm.ppf((no)/(len(x)+1))-norm.ppf(1/(len(x)+1)))
norm_arr=norm_arr/max(norm_arr)#Normalization
x.sort()#Sort x in ascending order

#Change y-axis display
scale =[]
list_axis =[0.0001,0.001,0.01,0.05,0.1,0.2,0.3,0.5,0.7,0.8,0.9,0.95,0.99,0.999,0.9999]
for no in list_axis:
   scale.append(norm.ppf(no)-norm.ppf(0.0001))
scale=scale/max(scale)

#drawing
fig, ax = plt.subplots(figsize=(8, 4))
linestyles = '-'
ax.grid(True)
ax.legend(loc='right')
ax.set_title('Cumulative step histograms')
ax.set_xlabel('data')
ax.set_ylabel('Percentage')
plt.yticks(scale,list_axis)
ax.plot(x,norm_arr,label='linear',marker='o',markersize=1.0,linewidth=0.1,linestyle=linestyles)

plt.show()

When executed, the above Figure 2 will be output as it is.

Recommended Posts

CUM_plot, which I often see at the manufacturing site, did not fall on the net, so I made it with python
Life game with Python [I made it] (on the terminal & Tkinter)
I made a segment tree with python, so I will introduce it
I couldn't import the python module with VSCODE, but I could do it on jupyterlab, so I searched for the cause (2)
Code memo that I was having trouble with not being on the discord.py site
When writing to a csv file with python, a story that I made a mistake and did not meet the delivery date
I couldn't import the python module with VSCODE, but I could do it on juoyterlab, so I'm talking about finding the cause.
I made a net news notification app with Python
I made a function to crop the image of python openCV, so please use it.
What I did to welcome the Python2 EOL with confidence
[I made it with Python] XML data batch output tool
[Python] Tensorflow 2.0 did not support Python 3.8, so the story of downgrading Python
Hannari Python At the LT meeting in December, I made a presentation on "Python and Bayesian statistics".
I made something with python that NOW LOADING moves from left to right on the terminal
I tried using "Asciichart Py" which can draw a beautiful graph on the console with Python.