-
Notifications
You must be signed in to change notification settings - Fork 11
/
simple_plot.py
129 lines (107 loc) · 4.06 KB
/
simple_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import os
import glob
import numpy as np
import scipy
import matplotlib
import matplotlib.pylab as plt
import datetime
import time
import random
import astropy
from astropy.io import fits
from astropy import units as u
from astropy import table
import pdb
plt.rcParams['figure.figsize'] = (12,8)
def plotData(NQuery,table,FigureStrBase,SurfMin,SurfMax,VDispMin,VDispMax,RadMin,RadMax) :
"""
This is where documentation needs to be added
Parameters
----------
NQuery
FigureStrBase : str
The start of the output filename, e.g. for "my_file.png" it would be
my_file
SurfMin
SurfMax
VDispMin
VDispMax
RadMin
RadMax
"""
plt.clf()
# d = table.Table.read("merged_table.ipac", format='ascii.ipac')
d = table
Author = d['Names']
Run = d['IDs']
SurfDens = d['SurfaceDensity']
VDisp = d['VelocityDispersion']
Rad = d['Radius']
IsSim = (d['IsSimulated'] == 'True')
UseSurf = (SurfDens > SurfMin) & (SurfDens < SurfMax)
UseVDisp = (VDisp > VDispMin) & (VDisp < VDispMax)
UseRad = (Rad > RadMin) & (Rad < RadMax)
Use = UseSurf & UseVDisp & UseRad
Obs = (~IsSim) & Use
Sim = IsSim & Use
UniqueAuthor = set(Author[Use])
NUniqueAuthor = len(UniqueAuthor)
#colors = random.sample(matplotlib.colors.cnames, NUniqueAuthor)
colors = list(plt.cm.jet(np.linspace(0,1,NUniqueAuthor)))
random.shuffle(colors)
plt.loglog()
markers = ['o','s']
for iAu,color in zip(UniqueAuthor,colors) :
UsePlot = (Author == iAu) & Use
ObsPlot = ((Author == iAu) & (~IsSim)) & Use
SimPlot = ((Author == iAu) & (IsSim)) & Use
if any(ObsPlot):
plt.scatter(SurfDens[ObsPlot], VDisp[ObsPlot], marker=markers[0],
s=(np.log(np.array(Rad[ObsPlot]))-np.log(np.array(RadMin))+0.5)**3.,
color=color, alpha=0.5)
if any(SimPlot):
plt.scatter(SurfDens[SimPlot], VDisp[SimPlot], marker=markers[1],
s=(np.log(np.array(Rad[SimPlot]))-np.log(np.array(RadMin))+0.5)**3.,
color=color, alpha=0.5)
if any(Obs):
plt.scatter(SurfDens[Obs], VDisp[Obs], marker=markers[0],
s=(np.log(np.array(Rad[Obs]))-np.log(np.array(RadMin))+0.5)**3.,
facecolors='none', edgecolors='black',
alpha=0.5)
if any(Sim):
plt.scatter(SurfDens[Sim], VDisp[Sim], marker=markers[1],
s=(np.log(np.array(Rad[Sim]))-np.log(np.array(RadMin))+0.5)**3.,
facecolors='none', edgecolors='black',
alpha=0.5)
plt.xlabel('$\Sigma$ [M$_{\odot}$ pc$^{-2}$]', fontsize=16)
plt.ylabel('$\sigma$ [km s$^{-1}$]', fontsize=16)
ax = plt.gca()
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
# Put a legend to the right of the current axis
ax.legend(UniqueAuthor, loc='center left', bbox_to_anchor=(1.0, 0.5), prop={'size':12}, markerscale = .7, scatterpoints = 1)
plt.xlim((SurfMin.to(u.M_sun/u.pc**2).value,SurfMax.to(u.M_sun/u.pc**2).value))
plt.ylim((VDispMin.to(u.km/u.s).value,VDispMax.to(u.km/u.s).value))
plt.show()
plt.savefig(FigureStrBase+NQuery+'.png',bbox_inches='tight',dpi=150)
plt.savefig(FigureStrBase+NQuery+'.pdf',bbox_inches='tight',dpi=150)
def clearPlotOutput(FigureStrBase,TooOld) :
for fl in glob.glob(FigureStrBase+"*.png") + glob.glob(FigureStrBase+"*.pdf"):
now = time.time()
if os.stat(fl).st_mtime < now - TooOld :
os.remove(fl)
def timeString() :
TimeString=datetime.datetime.now().strftime("%Y%m%d%H%M%S%f")
return TimeString
SurfMin = 1e-1*u.M_sun/u.pc**2
SurfMax = 1e5*u.M_sun/u.pc**2
VDispMin = 1e-1*u.km/u.s
VDispMax = 3e2*u.km/u.s
RadMin = 1e-2*u.pc
RadMax = 1e3*u.pc
NQuery=timeString()
FigureStrBase='Output_Sigma_sigma_r_'
TooOld=300
clearPlotOutput(FigureStrBase,TooOld)
plotData(NQuery,FigureStrBase,SurfMin,SurfMax,VDispMin,VDispMax,RadMin,RadMax)
#d.show_in_browser(jsviewer=True)