วิธีปรับขนาดแผนที่ความร้อนใน seaborn


คุณสามารถใช้อาร์กิวเมนต์ figsize เพื่อระบุขนาด (เป็นนิ้ว) ของแผนที่ความร้อน ของ Seaborn :

 #specify size of heatmap
fig, ax = plt. subplots (figsize=(15, 5))

#create seaborn heatmap
sns. heatmap (df)

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

ตัวอย่าง: ปรับขนาดของแผนที่ความร้อนใน Seaborn

สำหรับตัวอย่างนี้ เราจะใช้ชุดข้อมูลทางทะเลที่เรียกว่า Flights ซึ่งมีจำนวนผู้โดยสารทางอากาศที่เดินทางในแต่ละเดือนตั้งแต่ปี 1949 ถึง 1960:

 import matplotlib. pyplot as plt
import seaborn as sns

#load "flights" dataset
data = sns. load_dataset (“ flights ”)
data = data. pivot (" month ", " year ", " passengers ")

#view first five rows of dataset
print ( data.head ())

year 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
month                                                                        
Jan 112 115 145 171 196 204 242 284 315 340 360 417
Feb 118 126 150 180 196 188 233 277 301 318 342 391
Mar 132 141 178 193 236 235 267 317 356 362 406 419
Apr 129 135 163 181 235 227 269 313 348 348 396 461
May 121 125 172 183 229 234 270 318 355 363 420 472

ต่อไป เราจะสร้างแผนที่ความร้อนโดยใช้ขนาด ฟิก ขนาด 10 x 10:

 #specify size of heatmap
fig, ax = plt. subplots (figsize=(10, 10))

#create heatmap
sns. heatmap (data, linewidths= .3 )

โปรดทราบว่าแผนที่ความร้อนมีขนาดความสูงและความกว้างเท่ากัน

เราสามารถทำให้แผนที่ความร้อนแคบลงได้โดยการลดอาร์กิวเมนต์แรกของ figsize :

 #specify size of heatmap
fig, ax = plt. subplots (figsize=(5, 10))

#create heatmap
sns. heatmap (data, linewidths= .3 ) 

หรือเราอาจทำให้แผนที่ความร้อนกว้างขึ้นโดยการลดอาร์กิวเมนต์ที่สองให้เป็น figsize :

 #specify size of heatmap
fig, ax = plt. subplots (figsize=(10, 5))

#create heatmap
sns. heatmap (data, linewidths= .3 ) 

อย่าลังเลที่จะแก้ไขค่าใน figsize เพื่อเปลี่ยนขนาดของแผนที่ความร้อน

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

บทช่วยสอนต่อไปนี้จะอธิบายวิธีดำเนินการทั่วไปอื่นๆ ใน Seaborn:

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

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

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