# 匯入matplotlib.pyplot, numpy 包
import numpy as np
import matplotlib.pyplot as plt
# 新增主題樣式
plt.style.use("mystyle")
# 設定圖的大小,新增子圖
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
#繪製sin, cos
x = np.arange(-np.pi, np.pi, np.pi / 100)
y1 = np.sin(x)
y2 = np.cos(x)
sin, = ax.plot(x, y1, color="red", label="sin")
cos, = ax.plot(x, y2, color="blue", label="cos")
ax.set_ylim([-1.2, 1.2])
# 第二種方式 拆分顯示
sin_legend = ax.legend(handles=[sin], loc="upper right")
ax.add_artist(sin_legend)
ax.legend(handles=[cos], loc="lower right")
plt.show()
for color in ["red", "green"]:
n = 750
x, y = np.random.rand(2, n)
scale = 200.0 * np.random.rand(n)
ax.scatter(x, y, c=color, s=scale,
label=color, alpha=0.3,
edgecolors="none")
ax.legend()
ax.grid(True)
# 匯入matplotlib.pyplot, numpy 包
import numpy as np
import matplotlib.pyplot as plt
# 新增主題樣式
plt.style.use("mystyle")
# 設定圖的大小,新增子圖
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
#繪製sin, cos
x = np.arange(-np.pi, np.pi, np.pi / 100)
y1 = np.sin(x)
y2 = np.cos(x)
sin, = ax.plot(x, y1, color="red", label="sin")
cos, = ax.plot(x, y2, color="blue", label="cos")
ax.set_ylim([-1.2, 1.2])
# 第二種方式 拆分顯示
sin_legend = ax.legend(handles=[sin], loc="upper right")
ax.add_artist(sin_legend)
ax.legend(handles=[cos], loc="lower right")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
# 新增主題樣式
plt.style.use("mystyle")
# 設定圖的大小,新增子圖
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
for color in ["red", "green"]:
n = 750
x, y = np.random.rand(2, n)
scale = 200.0 * np.random.rand(n)
ax.scatter(x, y, c=color, s=scale,
label=color, alpha=0.3,
edgecolors="none")
ax.legend()
ax.grid(True)
plt.show()