#題目:分別作 y=2^x , y=(1/2)^x 的函數圖形
#Python 程式碼如下
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-3, 3, 100, endpoint=True)
y1 = np.power(2,X)
y2 = np.power(0.5,X)
plt.figure(figsize=(8,6),dpi=80)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.plot(X, y1, color="red", linewidth=1.0, linestyle="-", label="$y=2^x$")
plt.plot(X, y2, color="green", linewidth=1.0, linestyle="-", label="$y=(1/2)^x$")
plt.legend(loc='upper left')
plt.show()
# 輸出結果如下: