1、自变量的误差条
代码
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei' # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False # 使坐标轴刻度表签正常显示正负号
x = np.arange(17)
error = np.random.rand(17)
y = np.power(x, 2)
plt.figure('百里希文', facecolor='lightyellow')
plt.plot(x, y, 'gs--', mfc='y')
plt.errorbar(x, y, fmt='None', xerr=error, ecolor='r')
plt.xlabel('x')
plt.ylabel('x 的平方')
plt.grid(1, axis='both')
plt.show()
图形
2、应变量的误差条
代码
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei' # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False # 使坐标轴刻度表签正常显示正负号
x = np.arange(17)
error = np.random.rand(17)
y = np.sqrt(x)
plt.figure('百里希文', facecolor='lightyellow')
plt.plot(x, y, 'yd--', mfc='g')
plt.errorbar(x, y, fmt='None', yerr=error, ecolor='r')
plt.xlabel('x')
plt.ylabel('x 的平方根')
plt.grid(1, axis='both')
plt.show()
图形
3 、混合图形
代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = 'SimHei' # 使图形中的中文正常编码显示
plt.rcParams['axes.unicode_minus'] = False # 使坐标轴刻度表签正常显示正负号
x = np.arange(17)
error = np.random.rand(17)
y1 =np.power(x, 2)
y2 = np.sqrt(x)
plt.figure('百里希文', facecolor='lightyellow')
ax = plt.gca()
ax.plot(x, y1, 'yd--', mfc='g')
ax.errorbar(x, y1, fmt='None', yerr=error, xerr=error, ecolor='r', marker='d')
ax.set_ylabel('x 的平方根')
ax.set_xlabel('x')
ax.xaxis.grid(1, 'both')
ax.yaxis.grid(1, 'both')
ax2 = ax.twinx()
ax2.plot(x, y2, 'gh-.', mfc='y')
ax2.errorbar(x, y2, fmt='None', yerr=error, xerr=error, ecolor='r')
ax2.set_ylabel('x 的平方根根')
plt.show()
图形
。。。。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章