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

การเปลี่ยนสีและเครื่องหมายของแต่ละจุดโดยใช้ Seaborn jointplot


ในการเปลี่ยนสีและเครื่องหมายของแต่ละจุดโดยใช้ Seaborn jointplot เราสามารถทำตามขั้นตอนต่อไปนี้ -

  • กำหนดขนาดรูปและปรับช่องว่างภายในระหว่างและรอบๆ แผนผังย่อย

  • โหลดชุดข้อมูลตัวอย่างจากที่เก็บออนไลน์ (ต้องใช้อินเทอร์เน็ต)

  • ใช้ jointplot() วิธีการพล็อตข้อมูลเคล็ดลับ

  • ใช้ cla() วิธีการล้างแกนปัจจุบัน

  • ทำรายการสีและเครื่องหมายสำหรับแต่ละจุด

  • ตั้งค่าป้ายกำกับแกนโดยใช้ 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()

ผลลัพธ์

การเปลี่ยนสีและเครื่องหมายของแต่ละจุดโดยใช้ Seaborn jointplot