[준비물]
아나콘다의 spyder 또는 구글 드라이브의 colab
from google.colab import drive
drive.mount('/content/drive/')
import numpy as np
import csv
import pandas as pd
import matplotlib.pyplot as plt
# 거리에 따른 복사평형과, 반구로 가정한 유효온도
# 상수
a = 5.67e-8
pi = np.pi
# 거리 범위
d = np.linspace(0.001, 100, 10000) * 149.6e9
# 광도 계산
L1 = (4*pi*d**2)*a*(((273.15))**4)*2
L2 = (4*pi*d**2)*a*(((373.15))**4)*2
L_sun = 3.846e+26
# 상대적 광도 계산
L1_rel = L1 / L_sun
L2_rel = L2 / L_sun
# AU 단위로 변환
d_au = d / 149.6e9
# 그래프 그리기
plt.plot(d_au, L1_rel, label='T=0')
plt.plot(d_au, L2_rel, label='T=100')
filename = '/content/drive/MyDrive/외계행성.csv'
# CSV 파일 읽기
df = pd.read_csv(filename)
# L을 y축값으로, SEP를 x축값으로 설정하여 산점도 그리기.
plt.scatter(df['SEP'], df['L'])
# PLANETDISCMETH의 변수들을 다른 색깔의 점으로 찍기.
unique_discmeth = df['PLANETDISCMETH'].unique()
colors = ['red', 'green', 'blue', 'orange', 'purple', 'black', 'white'] # 색상 리스트를 원하는 대로 설정합니다.
for i, discmeth in enumerate(unique_discmeth):
subset = df[df['PLANETDISCMETH'] == discmeth]
plt.scatter(subset['SEP'], subset['L'], color=colors[i], label=discmeth)
count_by_discmeth = df['PLANETDISCMETH'].value_counts()
print(count_by_discmeth)
# 그래프 꾸미기
plt.title('Exoplanets')
plt.xlabel('Distance (AU)')
plt.ylabel('Relative Luminosity')
plt.xscale('log')
# plt.yscale('log')
plt.legend()
plt.ylim(0, 20)
plt.xlim(0, 100)
# 그래프 보여주기
plt.show()
아래는 결과입니다.
힌트