如何在 Matplotlib 中僅顯示左側和下側邊框框框邊框?
若要顯示或隱藏 matplotlib 中的邊框框框,我們可以使用脊線(值可以是 right、left、top 或 bottom)和 set_visible() 方法,將可見性設定為 True 或 False。
步驟
使用 numpy 建立 x 和 y 資料點。
建立一張圖,並使用 subplots() 方法新增一組子圖。
使用 plot() 方法繪製 x 和 y 資料點,其中 linewidth=7,color=red。
將 left 和 bottom 的可見性設定為 True,將 top 和 right 的可見性設定為 False。
要顯示圖片,請使用 ** show() ** 方法。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-2, 2, 10) y = np.sin(x) fg, ax = plt.subplots() ax.plot(x, y, lw=7, c='red') ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['left'].set_visible(True) ax.spines['bottom'].set_visible(True) plt.show()
輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP