import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y = x**2 #Left-hand estimate rect_x = np.linspace(0, 10, 11) rect_y = rect_x**2 rect_height = rect_y[:-1] rect_width = rect_x[1:] - rect_x[:-1] #Right-hand estimate rect_x_r = np.linspace(-1, 9, 11) rect_y_r = (rect_x_r+1)**2 rect_height_r = rect_y_r[1:] rect_width_r = rect_x_r[1:] - rect_x_r[:-1] plt.bar(rect_x_r[1:], rect_height_r, rect_width_r, align='edge', alpha=0.5, color='orange', label='Right-hand estimate') plt.bar(rect_x[:-1], rect_height, rect_width, align='edge', alpha=0.5, color='blue', label='Left-hand estimate') plt.plot(x, y, label='y = x^2') plt.xlabel('x') plt.ylabel('y') plt.title('y = x^2 and Left/Right-hand estimate') plt.legend() plt.grid() plt.show()
🦂️🐶宇宙 樂園 邀你共賞🐶🦂️ StarTrek / GalaxyQuest NASA 成立那年出生 航海家 1 號發射那年上大學 SN1987a 大放異彩那年拿到博士學位 出生那年 NASA 成立 上大學 那年 航...