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

การเปลี่ยนสีและ Marker ของแต่ละจุดใน Seaborn Jointplot


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

  • กำหนดขนาดรูปภาพและปรับระยะห่างระหว่างและรอบๆ subplots
  • โหลดชุดข้อมูลตัวอย่างจากออนไลน์ (ต้องอินเทอร์เน็ต)
  • ใช้ jointplot() พล็อตข้อมูล tips
  • ใช้ cla() ล้าง axes ปัจจุบัน
  • สร้างรายการสีและ marker สำหรับแต่ละจุด
  • ตั้งค่า axes labels ด้วย set_axis_labels()
  • ใช้เมธอด show() เพื่อแสดงรูปภาพ

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

from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np

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

tips = sns.load_dataset("tips")
g = sns.jointplot("total_bill", "tip", data=tips, height=4.50)
g.ax_joint.cla()
colors = np.random.random((len(tips), 3))
markers = ['v', '^', '<', '*', 'o'] * 100
for i, row in enumerate(tips.values):
    g.ax_joint.plot(row[0], row[1], color=colors[i], marker=markers[i])
g.set_axis_labels('total bill', 'tip', fontsize=10)
plt.show()

ผลลัพธ์

การเปลี่ยนสีและ Marker ของแต่ละจุดใน Seaborn Jointplot