เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การพล็อตข้อมูล

ใน Python ทุกอย่างเป็นออบเจ็กต์ แม้แต่โมดูล แบบฝึกหัดนี้ให้ทบทวนการใช้งานอินเทอร์เฟซเชิงออบเจ็กต์ของไลบรารี matplotlib เพื่อแสดงผลข้อมูลในรูปแบบที่ยืดหยุ่นและขยายได้มากขึ้น ขั้นตอนการพล็อตโดยทั่วไปมีดังนี้

import matplotlib.pyplot as plt 
fig, axis = plt.subplots()
axis.plot(x, y, color="green", linestyle="--", marker="s")
plt.show()

context figure

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Linear Modeling in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • ใช้ plt.subplots() เพื่อสร้างออบเจ็กต์ figure และ axis
  • ข้อมูลถูกเตรียมไว้ให้แล้วในอาร์เรย์ numpy สองชุด ได้แก่ times และ distances
  • ใช้ axis.plot() เพื่อพล็อต times บนแกนนอน และ distances บนแกนตั้ง
  • ระบุ keyword arguments linestyle=" ", marker="o" และ color="red" เมื่อเรียกใช้ axis.plot()

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create figure and axis objects using subplots()
fig, axis = plt.____()

# Plot line using the axis.plot() method
line = axis.plot(____ , ____ , linestyle="____", marker="____", color="____")

# Use the plt.show() method to display the figure
plt.____()
แก้ไขและรันโค้ด