ขั้นตอนการทำงาน
- กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
- สร้างข้อมูล x และ y ด้วย numpy
- สร้าง figure และชุด subplots
- พล็อต x และ y ด้วยเมธอด hexbin()
- ตั้งชื่อเรื่องของกราฟ
- ใช้เมธอด 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()
ผลลัพธ์
