如何從 Pylab 生成的圖片中移除 Y 軸?


為了從 Pylab 生成的圖片中移除 Y 軸,我們可以獲取該繪圖的當前座標軸,然後使用 set_visible(False) 方法。

步驟

  • 設定圖形尺寸並調整子圖之間的填充。

  • 使用 numpy 建立 x 和 y 資料點。

  • 使用 plot() 方法繪製 x 和 y 資料點。

  • 獲取當前圖形的當前座標軸。

  • 將 Y 軸的可視性設定為 False。

  • 要顯示圖形,請使用 show() 方法。

示例

import numpy as np
import pylab

# Set the figure size
pylab.rcParams["figure.figsize"] = [7.50, 3.50]
pylab.rcParams["figure.autolayout"] = True

# Random data points
x = np.random.rand(10)
y = np.random.rand(10)

# Plot the data points
pylab.plot(x, y)

# Get the current axis
ax = pylab.gca()

# Set Y-axis visibility to False
ax.yaxis.set_visible(False)

# Display the plot
pylab.show()

輸出

它將生成以下輸出 -

更新於: 02-Feb-2022

267 次瀏覽

開啟你的職業

完成課程以獲得認證

開始
廣告
© . All rights reserved.