การปิดการแสดง Output Object ใน Jupyter
ใช้ semicolon (;) หรือกำหนดให้ตัวแปร _ เพื่อไม่ให้แสดง representation ของ artists
วิธีการ
- import numpy as np, matplotlib.pyplot as plt
- สร้างข้อมูล x
- พล็อตปกติ: plt.plot(x) จะแสดง output เช่น
Out[4]: [] - ใช้ semicolon: plt.plot(x); ไม่แสดง output
- หรือกำหนดตัวแปร: _ = plt.plot(x) ก็ไม่แสดง output
ตัวอย่างใน Jupyter
In [1]: import numpy as np
In [2]: from matplotlib import pyplot as plt
In [3]: x = np.linspace(1, 10, 1000)
In [4]: plt.plot(x)
Out[4]: []
In [5]: plt.plot(x);
In [6]: _ = plt.plot(x)
In [7]:
คำอธิบาย
Semicolon ทำให้ Jupyter ไม่แสดงค่าคืนของ expression ตัวสุดท้าย