반응형

 

출처: https://gall.dcinside.com/board/view/?id=superidea&no=174651

 

 

Classification Gt C Tons (t) Ratio (%)
Plants (including 10 Gt C cultivated) 450.0 450,000,000,000,000 82.10%
Bacteria 70.0 70,000,000,000,000 12.77%
Fungi 12.0 12,000,000,000,000 2.19%
Protists 4.0 4,000,000,000,000 0.73%
Archaea 7.0 7,000,000,000,000 1.28%
Viruses 0.2 200,000,000,000 0.04%
All Animals 2.5 2,500,000,000,000 0.46%
Fish 0.7 700,000,000,000 0.13%
Arthropods 1.0 1,000,000,000,000 0.18%
Mollusks 0.2 200,000,000,000 0.04%
Annelids 0.2 200,000,000,000 0.04%
Nematodes 0.02 20,000,000,000 0.00%
Cnidarians and others 0.1 100,000,000,000 0.02%
Wild Birds 0.002 2,000,000,000 0.00%
Wild Mammals (land) 0.003 3,000,000,000 0.00%
Wild Mammals (marine) 0.004 4,000,000,000 0.00%
Livestock 0.1 100,000,000,000 0.02%
Humans 0.06 60,000,000,000 0.01%


출처를 인용하여 한눈에 보기 쉽게 만든 테이블

 

 

 

총량 크기의 순위를 매긴 막대 그래프

 

Python Code 로 생성한 Treemap

 



전세계 생물의 무게 총량을 분류해놓은 게시물인데요
최신 자료를 찾아보았으나 2018년이 최신자료였던 관계로
해당 자료를 인용하여 제작하였습니다.
상세한 자료를 한눈에 간단하게 볼 수 있는 Treemap과 List를 포함한 형식을 Python 으로 만들어보았습니다.

만약 Treemap 으로 그래프를 제작하고자 한다면 아래의 소스코드를 이용하여 제작하시면 됩니다.


Python Source Code를 첨부할테니 참조하시길 바랍니다.

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import squarify


# 아래 예시는 임시 데이터입니다. 실제 데이터로 교체하세요.
data = {
    "Classification": [
        "Plants (Man-grown Included 10.0 GT)", "Bacteria", "Fungi", "Protists", "Archaea", "Viruses",
        "All Animals", "Fish", "Arthropods", "Mollusks", "Annelids", "Nematodes",
        "Cnidarians and others", "Wild Birds", "Wild Mammals (land)", "Wild Mammals (marine)",
        "Livestock", "Humans"
    ],
    "Giga_Ton": [
        450.0, 70.0, 12.0, 4.0, 7.0, 0.2,
        2.5, 0.7, 1.0, 0.2, 0.2, 0.02,
        0.1, 0.002, 0.003, 0.004,
        0.1, 0.06
    ],
    "ton": [
        450_000_000_000_000, 70_000_000_000_000, 12_000_000_000_000, 4_000_000_000_000,
        7_000_000_000_000, 200_000_000_000, 2_500_000_000_000, 700_000_000_000,
        1_000_000_000_000, 200_000_000_000, 200_000_000_000, 20_000_000_000,
        100_000_000_000, 2_000_000_000, 3_000_000_000, 4_000_000_000,
        100_000_000_000, 60_000_000_000
    ],
    "Ratio": [
        82.10, 12.77, 2.19, 0.73, 1.28, 0.04,
        0.46, 0.13, 0.18, 0.04, 0.04, 0.00,
        0.02, 0.00, 0.00, 0.00,
        0.02, 0.01
    ]
}
df = pd.DataFrame(data).sort_values(by="ton", ascending=False)



# 트리맵 좌표 생성
sizes = df["ton"].values
labels = df["Classification"].values
normed = squarify.normalize_sizes(sizes, 100, 100)
rects = squarify.squarify(normed, 0, 0, 100, 100)

# 서브플롯 생성: 1행 2열 (트리맵 | 리스트)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(24, 12), gridspec_kw={'width_ratios': [3, 1]})

# 트리맵 그리기
squarify.plot(sizes=sizes, ax=ax1, color=plt.cm.tab20.colors, alpha=0.85, label=None)
ax1.set_title("Global Biomass Treemap", fontsize=20)
ax1.axis("off")

# 수동 라벨 추가 (면적 큰 박스에만)
for i, rect in enumerate(rects):
    x = rect['x'] + rect['dx'] / 2
    y = rect['y'] + rect['dy'] / 2
    if rect['dx'] > 2 and rect['dy'] > 2:
        ax1.text(x, y, labels[i],
                 va='center', ha='center', fontsize=9, color='black')

# 오른쪽 리스트 출력
ax2.axis("off")
ax2.set_title("Classification & Biomass (Giga Ton)", fontsize=16, loc='left')

for i, (name, Giga_Ton) in enumerate(zip(df["Classification"], df["Giga_Ton"])):
    ax2.text(0.00, 1 - i * 0.05, name, fontsize=12, va='top', ha='left')
    ax2.text(0.95, 1 - i * 0.05, str(float(Giga_Ton)) + " Giga Ton", fontsize=12, va='top', ha='right')

plt.tight_layout()
plt.savefig("biomass_with_list.png", dpi=300)
plt.show()

 

 

 

반응형

+ Recent posts