如何在 Matplotlib 中繪製六邊形柱狀圖?


要在 matplotlib 中繪製六邊形柱狀圖,我們可以採取以下步驟:

  • 設定圖表大小並調整子圖周圍和之間的填充。

  • 使用 numpy 建立 x 和 y 資料點。

  • 建立一個圖形和一組子圖。

  • 使用 **hexbin()** 方法繪製 x 和 y。

  • 設定曲線的標題。

  • 使用 **show()** 方法顯示圖形。

示例

import numpy as np
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = 2 * np.random.randn(5000)
y = x + np.random.randn(5000)

fig, ax = plt.subplots()
_ = ax.hexbin(x[::10], y[::10], gridsize=20, cmap='plasma')

ax.set_title('Hexbin Histogram')

plt.show()

輸出

更新於:2021 年 6 月 3 日

428 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.