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

วิธีใช้ Marker ต่างกันสำหรับจุดต่างๆ ใน Pylab Scatter Plot (Matplotlib)

ในการใช้ marker ต่างกันสำหรับจุดต่างๆ ใน Pylab (Pyplot) scatter plot เราสามารถใช้ขั้นตอนต่อไปนี้:

  • ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
  • เริ่มต้นตัวแปร N สำหรับจำนวนข้อมูลตัวอย่าง
  • สร้างจุดข้อมูล x และ y แบบสุ่ม
  • สร้างลิสต์ของ markers
  • Zip x, y และ markers เข้าด้วยกัน
  • วนลูปอ็อบเจ็กต์ zip และพลอตจุดข้อมูลด้วย marker ต่างกัน
  • เพื่อแสดงรูป ใช้เมธอด show()

ตัวอย่าง

import numpy as np
from matplotlib import pyplot as plt

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

N = 10
x = np.random.rand(N)
y = np.random.rand(N)
markers = ["d", "v", "s", "*", "^", "d", "v", "s", "*", "^"]

for xp, yp, m in zip(x, y, markers):
    plt.scatter(xp, yp, marker=m, s=50)

plt.show()

ผลลัพธ์

วิธีใช้ Marker ต่างกันสำหรับจุดต่างๆ ใน Pylab Scatter Plot (Matplotlib)วิธีใช้ Marker ต่างกันสำหรับจุดต่างๆ ใน Pylab Scatter Plot (Matplotlib)