Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ปิดเครื่องหมายทิก (Tick Marks) บนแกนซ้าย/ล่างใน Matplotlib


ใช้ length=0 สำหรับ axes ในเมธอด tick_params()

ขั้นตอนการทำงาน

  • กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
  • สร้างข้อมูล x และ y ด้วย numpy
  • พล็อต x และ y ด้วย plot()
  • ใช้ tick_params() พร้อม length=0
  • ใช้เมธอด show() เพื่อแสดงรูปภาพ

ตัวอย่างโค้ด

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.linspace(-2, 2, 10)
y = np.sin(x)
plt.plot(x, y)
plt.tick_params(axis='both', which='both', length=0)
plt.show()

ผลลัพธ์

ปิดเครื่องหมายทิก (Tick Marks) บนแกนซ้าย/ล่างใน Matplotlib