一、基本介紹
Originerrorbar是Origin軟體中的一種統計圖表,用於表示數據集合中各數據點的誤差範圍和統計量。它在可視化數據和數據分析方面有著廣泛的應用,是科學研究和工程設計中不可或缺的一種圖表類型。
Originerrorbar包括數值坐標軸和誤差條,誤差條可以表示數據的標準差、方差、置信區間等統計信息,展示出數據的可靠程度和差異性。
下面是Originerrorbar的基本示例代碼:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = np.linspace(0.05, 0.2, 10) fig, ax = plt.subplots() ax.errorbar(x, y + 2, yerr=yerr, label='both limits (default)') plt.show()
二、不同類型的誤差條
Originerrorbar提供了多種類型的誤差條,包括標準誤差、置信區間、百分比誤差、標準偏差等等。不同的統計信息反映了不同的數據特徵,適用於不同的數據集合和分析需求。
1. 標準誤差誤差條
標準誤差誤差條表示樣本統計量與總體參數之間的差異,是常用的誤差條類型之一。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = np.std(y) / np.sqrt(len(y)) fig, ax = plt.subplots() ax.errorbar(x, y, yerr=yerr,fmt='-o') plt.show()
2. 置信區間誤差條
置信區間誤差條表示樣本統計量的可信程度,反映了總體參數的未知真實值可能落在哪個區間內。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = 1.96 * np.std(y) / np.sqrt(len(y)) fig, ax = plt.subplots() ax.errorbar(x, y, yerr=yerr,fmt='-o') plt.show()
3. 百分比誤差條
百分比誤差條表示數據值的相對變化幅度,通常用於比較不同數據集合之間的差異。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = 0.1 * y fig, ax = plt.subplots() ax.errorbar(x, y, yerr=yerr,fmt='-o') plt.show()
三、多種展示方式
除了基本的誤差條展示之外,Originerrorbar還提供了多種展示方式,可以更直觀地展示數據分布和差異性。
1. 對稱誤差條
對稱誤差條展示了數據點的誤差範圍,只展示數據的上下誤差範圍而不以方向為區分,適用於誤差範圍對於數據的影響相等的情況。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = np.linspace(0.05, 0.2, 10) fig, ax = plt.subplots() ax.errorbar(x, y, yerr=yerr, fmt='o') plt.show()
2. 非對稱誤差條
非對稱誤差條展示了數據點的不對稱誤差範圍,能夠更好地反映數據的實際情況。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) yerr = np.zeros((2, 10)) yerr[0, :] = 0.1 * y yerr[1, :] = 0.2 * y fig, ax = plt.subplots() ax.errorbar(x, y, yerr=yerr, fmt='o') plt.show()
3. 異常值誤差條
異常值誤差條展示了數據集合中的異常值和離群點,有助於識別數據分布中的重要特徵。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) y[5] = 3.0 fig, ax = plt.subplots() ax.errorbar(x, y, yerr=0.1, fmt='-o', ecolor='r') plt.show()
四、結合其他圖表類型展示數據
Originerrorbar可以和其他圖表類型進行結合,展示不同的數據特徵和分析內容。
1. 直方圖與誤差條
直方圖和誤差條結合可以更好地展示數據的分布情況和置信區間,有助於識別數據中存在的多種特徵。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt x = np.random.normal(size=100) y = np.random.normal(size=100) xbins = np.linspace(-4, 4, 20) fig, ax = plt.subplots() ax.hist(x, bins=xbins, color='lightblue') ax.errorbar(xbins[:-1], ax.hist(x, bins=xbins, color='lightblue')[0], yerr = 5* np.sqrt(ax.hist(x, bins=xbins)[0]), fmt="none",linewidth=2, elinewidth=0.7, capsize=4, capthick=0.7,label='x_data') ax.hist(y, bins=xbins, color='salmon') ax.errorbar(xbins[:-1], ax.hist(y, bins=xbins, color='salmon')[0], yerr = 5 * np.sqrt(ax.hist(y, bins=xbins)[0]), fmt="none",linewidth=2, elinewidth=0.7, capsize=4, capthick=0.7,label='y_data') plt.legend(); plt.show()
2. 箱線圖與誤差條
箱線圖和誤差條結合可以更好地展示數據集合的分位數分布和離群點情況,有助於較為全面地了解數據分布的特徵和變化。示例代碼如下:
import numpy as np import matplotlib.pyplot as plt np.random.seed(10) data = [np.random.normal(0, std, size=100) for std in range(1, 4)] fig, ax = plt.subplots() ax.boxplot(data, notch=True, positions=[1, 2, 3]) for i in range(len(data)): y = data[i] x = np.random.normal(1+i, 0.05, size=len(y)) ax.errorbar(x, y, fmt='none', yerr=1.3, color='k') plt.show()
五、應用實例展示
Originerrorbar在科學研究和工程設計中應用廣泛,下面是一些典型的應用實例。例如,生命科學研究中通常採用Originerrorbar表示不同藥物處理下基因表達水平的變化;工程設計中Originerrorbar表示同一零件在不同加工工藝下的尺寸差異。
原創文章,作者:AOKOK,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/351623.html