ในการหยุด interaction สำหรับ figure เฉพาะใน Jupyter notebook แบบโปรแกรม เราสามารถใช้ plt.off() เพื่อหยุด interaction ใดๆ หลังจากนั้น
รันคำสั่งต่อไปนี้ตามลำดับ:
- %matplotlib auto
- import matplotlib.pyplot as plt
- plt.rcParams["figure.figsize"] = [7.50, 3.50]
- plt.rcParams["figure.autolayout"] = True
- สร้าง figure และชุด subplots
- พลอตเส้นบนแกน (จากขั้นตอน 5)
- ปิด interaction
- เพื่อแสดงรูป ใช้เมธอด show()
ตัวอย่าง
In [1]: %matplotlib auto
Using matplotlib backend: Qt5Agg
In [2]: import matplotlib.pyplot as plt
In [3]: plt.rcParams["figure.figsize"] = [7.50, 3.50]
...: plt.rcParams["figure.autolayout"] = True
In [4]: fig, ax = plt.subplots()
In [5]: ax.plot([2, 4, 7, 5, 4, 1])
Out[5]: []
In [6]: plt.ioff()
In [7]: ax.plot([1, 1, 2, 1, 2, 2])
Out[7]: []
In [8]: fig.show()
In [9]:
ผลลัพธ์
