Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.66 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Oct 29 04:44:24 2018
  5.  
  6. @author: danial
  7. """
  8.  
  9. # import packages
  10. import numpy as np
  11. import matplotlib.pyplot as plt
  12. import matplotlib.patheffects as PathEffects
  13. from matplotlib import rc
  14. rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
  15. ## for Palatino and other serif fonts use:
  16. #rc('font',**{'family':'serif','serif':['Palatino']})
  17. rc('text', usetex=True)
  18.  
  19. file = open("list-stars.txt")
  20. listoflines = file.readlines()
  21.  
  22. lines = []
  23. i = 1
  24.  
  25. for i in range(6,len(listoflines)):
  26.     line = listoflines[i]
  27.     lines.append(line)
  28.     i+=1
  29.  
  30. # define lists of attributes
  31.    
  32. names = []
  33. spectralclasses = []
  34. BVcolours = []
  35. UBcolours = []
  36. effTemps = []
  37. absolmags = []
  38. luminosities = []
  39.  
  40. i = 1
  41.  
  42. for i in range(len(lines)):
  43.     line = lines[i]
  44.     linesplit = line.split()
  45.  
  46.     name = linesplit[0]
  47.     names.append(name)
  48.    
  49.     spectralclass = linesplit[1]
  50.     spectralclasses.append(spectralclass)
  51.    
  52.     BVcolour = linesplit[2]
  53.     BVcolours.append(BVcolour)
  54.    
  55.     UBcolour = linesplit[3]
  56.     UBcolours.append(UBcolour)
  57.    
  58.     effTemp = linesplit[4]
  59.     effTemps.append(effTemp)
  60.    
  61.     absolmag = linesplit[5]
  62.     absolmags.append(absolmag)
  63.    
  64.    
  65.     luminosity = linesplit[6]
  66.     luminosities.append(luminosity)
  67.  
  68. # if you want to check, if all your lists are right, uncomment this passage
  69. '''
  70. print("names \n", names, "\n")
  71. print("spectralclasses \n", spectralclasses,"\n")
  72. print("BVcolours \n", BVcolours, "\n")
  73. print("UBcolours \n", UBcolours, "\n")
  74. print("effTemps \n", effTemps, "\n")
  75. print("absolmags \n", absolmags,"\n")
  76. print("luminosities \n", luminosities,"\n")
  77. '''
  78. X = []
  79. Y = []
  80. i = 0
  81.  
  82. for i in range(23):
  83.    
  84.     x = float(effTemps[i])
  85.     X.append(x)
  86.    
  87.     y = np.log10(float(luminosities[i]))
  88.     #y = float(luminosities[i])
  89.     Y.append(y)
  90.    
  91.     i+=1
  92.  
  93. print(X,"\n")
  94. print(Y)
  95.  
  96.  
  97. fig, ax = plt.subplots(figsize=(5,5), dpi = 300, facecolor = 'black')
  98.  
  99. plt.rc('text', usetex=True)
  100. plt.rc('font', family='serif')
  101.  
  102.  
  103. ax.spines['bottom'].set_color('white')
  104. ax.spines['left'].set_color('white')
  105.  
  106. ax.title.set_color('white')
  107. ax.yaxis.label.set_color('white')
  108. ax.xaxis.label.set_color('white')
  109. ax.tick_params(axis='x', colors='white')
  110. ax.tick_params(axis='y', colors='white')
  111.  
  112. # names of axes
  113. ax.set_title(r'Hertzsprung-Russel Diagramm')
  114. ax.set_xlabel(r'$ \displaystyle T_{eff} [\mathrm{K}]$', fontsize = 10)
  115. ax.set_ylabel(r'$ \displaystyle \log(L/L_{\odot}[\mathrm{mag}])$', fontsize = 10)
  116. ax.invert_xaxis()
  117.  
  118. # make some annotations
  119. i = 0
  120.  
  121. spectralcolor = []
  122.  
  123. for i in range(len(names)):
  124.    
  125.     if spectralclasses[i] == 'O':
  126.         c = 'darkblue'
  127.         spectralcolor.append(c)
  128.  
  129.     elif spectralclasses[i] == 'B':
  130.         c = 'cyan'
  131.         spectralcolor.append(c)
  132.    
  133.     elif spectralclasses[i] == 'A':
  134.         c = 'ivory'
  135.         spectralcolor.append(c)
  136.    
  137.     elif spectralclasses[i] == 'F':
  138.         c = 'beige'
  139.         spectralcolor.append(c)
  140.    
  141.     elif spectralclasses[i] == 'G':
  142.         c = 'wheat'
  143.         spectralcolor.append(c)
  144.    
  145.     elif spectralclasses[i] == 'K':
  146.         c = 'orange'
  147.         spectralcolor.append(c)
  148.    
  149.     elif spectralclasses[i] == 'M':
  150.         c = 'red'
  151.         spectralcolor.append(c)
  152.    
  153.     txt = ax.annotate( r'$ \displaystyle '+names[i]+'$', (X[i],Y[i]), color ='white', fontsize=7)
  154.     txt.set_path_effects([PathEffects.withStroke(linewidth=1, foreground='black')])
  155.     i+=1
  156.    
  157. ax.set_facecolor('black')
  158. ax.scatter(X,Y,color = spectralcolor)
  159.  
  160. # close and save file
  161. plt.savefig("HRD-plot.png", bbox_inches=0,  pad_inches = 0,  dpi = 300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement