
3、有顏色棒的散點圖
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
rng = np.random.RandomState(0)
x = rng.randn(50)
y = rng.randn(50)
colors = rng.rand(50)
sizes = 500 * rng.rand(50)
plt.scatter(x, y, c=colors, s=sizes, alpha=0.4,
? ? ? ? ? ? cmap='viridis')
plt.colorbar()
# 右邊有顏色棒
plt.xlabel("x軸")
plt.ylabel("y軸")
plt.title("有顏色棒的散點圖")
plt.show()
# 顯示圖形