Để ẩn output in ra của Matplotlib trong Python/Jupyter notebook:
- import numpy as np.
- from matplotlib import pyplot as plt.
- Tạo điểm x, ví dụ np.linspace(1, 10, 1000).
- Vẽ đường bằng plot().
- Để ẩn instance, dùng plt.plot(x); (có dấu chấm phẩy).
- Hoặc dùng _ = plt.plot(x).
Ví dụ
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]:
Kết quả
Out[4]: []