วิธีเพิ่มชื่อเรื่องให้กับแปลงทะเล (พร้อมตัวอย่าง)


หากต้องการเพิ่มชื่อเรื่องให้กับแผนผังทางทะเลรายการเดียว คุณสามารถใช้ฟังก์ชัน .set() ได้

ตัวอย่างเช่น ต่อไปนี้เป็นวิธีเพิ่มชื่อเรื่องลงใน Boxplot:

 sns. boxplot (data=df, x=' var1 ', y=' var2 '). set (title=' Title of Plot ')

หากต้องการเพิ่มชื่อเรื่องสากลให้กับโครงเรื่องแบบเหลี่ยมมุมทางทะเล คุณสามารถใช้ฟังก์ชัน .suptitle() ได้

ตัวอย่างเช่น ต่อไปนี้เป็นวิธีเพิ่มชื่อสากลให้กับ replot:

 #define relplot
rel = sns. relplot (data=df, x=' var1 ', y=' var2 ', col=' var3 ')

#add overall title to replot
rel. fig . suptitle (' Overall Title ')

ตัวอย่างต่อไปนี้แสดงวิธีใช้ฟังก์ชันเหล่านี้ในทางปฏิบัติ

ตัวอย่างที่ 1: เพิ่มชื่อเรื่องให้กับพล็อต Seaborn เดียว

รหัสต่อไปนี้แสดงวิธีการเพิ่มชื่อเรื่องลงใน Boxplot ของ Seaborn:

 import pandas as pd
import seaborn as sns
import matplotlib. pyplot as plt

#create fake data
df = pd. DataFrame ({' points ': [25, 12, 15, 14, 19, 23, 25, 29],
                   ' assists ': [5, 7, 7, 9, 12, 9, 9, 4],
                   ' team ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

#create boxplot
sns. boxplot (data=df, x=' team ', y=' points '). set (title=' Points by Team ') 

บ็อกซ์พล็อตเรื่อง Seaborn พร้อมชื่อเรื่อง

และโค้ดต่อไปนี้แสดงวิธีเพิ่มชื่อเรื่องให้กับ Marine Scatterplot:

 sns. scatterplot (data=df, x=' points ', y=' assists '). set (title=' Points vs. Assists ') 

โครงเรื่องกระจายท้องทะเลพร้อมชื่อเรื่อง

และโค้ดต่อไปนี้แสดงวิธีเพิ่มชื่อให้กับ Seaborn regplot:

 sns. regplot (data=df, x=' points ', y=' assists '). set (title=' Points vs. Assists ') 

พล็อตเรื่องทะเลที่มีชื่อเรื่อง

ตัวอย่างที่ 2: เพิ่มชื่อสากลให้กับพล็อตเรื่อง Seaborn Face

รหัสต่อไปนี้แสดงวิธีการเพิ่มชื่อเรื่องให้กับพล็อตเหลี่ยมเพชรพลอยของ Seaborn:

 import pandas as pd
import seaborn as sns
import matplotlib. pyplot as plt

#create fake data
df = pd. DataFrame ({' points ': [25, 12, 15, 14, 19, 23, 25, 29],
                   ' assists ': [5, 7, 7, 9, 12, 9, 9, 4],
                   ' team ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

#create relplot
rel = sns. relplot (data=df, x=' points ', y=' assists ', col=' team ')

#add overall title
rel. fig . suptitle (' Stats by Team ')

โครงเรื่องเหลี่ยมเพชรพลอยท้องทะเลพร้อมชื่อเรื่อง

นอกจากนี้เรายังสามารถใช้อาร์กิวเมนต์ subplots_adjust() เพื่อย้ายชื่อโดยรวมให้สูงขึ้นเล็กน้อย เพื่อไม่ให้รบกวนแต่ละพล็อต:

 #create relplot
rel = sns. relplot (data=df, x=' points ', y=' assists ', col=' team ')

#move overall title up
rel. fig . subplots_adjust (top= .8 )

#add overall title
rel. fig . suptitle (' Stats by Team ') 

แหล่งข้อมูลเพิ่มเติม

วิธีปรับขนาดฟิกเกอร์ของพล็อตเรื่อง Seaborn
วิธีเปลี่ยนตำแหน่งของตำนานใน Seaborn
วิธีเปลี่ยนป้ายกำกับแกนบนพล็อต Seaborn

เพิ่มความคิดเห็น

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *