Skip to content
Snippets Groups Projects
Commit caa47015 authored by Aldo Ignacio Arriola Cordova's avatar Aldo Ignacio Arriola Cordova
Browse files

diagramas Hertzsprung -Russell

parent d5fdd118
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Ejercicio 1
### Alumno: Aldo Arriola
#### Solución
para este problema se hará uso de la librería matplotlib en conjunto con numpy.
Debemos empezar por cargar los datos a partir de la lectura de los ficheros .csv y .txt.
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.collections import EllipseCollection
import matplotlib
```
%% Cell type:code id: tags:
``` python
!ls data
```
%% Output
dwarfs.csv giants.txt ms.csv supergiants.txt
%% Cell type:code id: tags:
``` python
data_dwarfs = np.loadtxt("data/dwarfs.csv", comments="#", delimiter=",", skiprows=1)
data_giants = np.loadtxt("data/giants.txt", comments="#", delimiter=" ", skiprows=1)
data_ms = np.loadtxt("data/ms.csv", comments="#", delimiter=",", skiprows=1)
data_supergiants = np.loadtxt("data/supergiants.txt", comments="#", delimiter=" ", skiprows=1)
```
%% Cell type:markdown id: tags:
#### Plot para segmentar por leyenda el tipo de estrella
%% Cell type:code id: tags:
``` python
fig, ax = plt.subplots(figsize=(14,10))
labels = ["Dwarfs", "Giants", "Main Sequence", "Supergiants"]
for k, data in enumerate([data_dwarfs, data_giants, data_ms, data_supergiants]):
ax.scatter(data[:,1], data[:,0], s=5*data[:,2],label=labels[k])
plt.yscale("log")
ax.invert_xaxis()
ax.set_title("Labeled type of star")
ax.set_xlabel("Temperature ($K$)")
ax.set_ylabel("Luminosity ($L_{sun}$)")
plt.legend()
```
%% Output
<matplotlib.legend.Legend at 0x7f27370d8f98>
%% Cell type:code id: tags:
``` python
# Agrupamos todos los conjutos de datos de cada tpo de estrella
data = np.concatenate((data_dwarfs, data_giants, data_ms, data_supergiants), axis=0)
```
%% Cell type:code id: tags:
``` python
# Colormap para representar la temperatura
colormap=plt.get_cmap("jet_r")
```
%% Cell type:code id: tags:
``` python
matplotlib.rcParams.update({'font.size': 16})
fig, ax = plt.subplots(figsize=(12,10))
# el tamano de las estrellas fue nultillicado x10
ax.scatter(data[:, 1], data[:, 0], s=10*data[:, 2], c=data[:, 1], cmap=colormap, edgecolor="k",linewidth=0.2)
plt.yscale("log")
ax.invert_xaxis()
ax.set_xlabel("Temperature (K)", fontsize=16)
ax.set_ylabel("Luminosity ($L_{sun}$)", fontsize=16)
ax.text(0.85,0.4, "Giant", weight="bold",transform=ax.transAxes)
ax.text(0.3,0.4, "Main Sequence", weight="bold",transform=ax.transAxes)
ax.text(0.6,0.9, "Supergiants", weight="bold",transform=ax.transAxes)
ax.text(0.7,0.1, "Dwarfs", weight="bold",transform=ax.transAxes)
ax.set_title("HR-diagram")
plt.savefig("Result-HR-diagram_.png", format="png")
```
%% Output
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment