-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex1.6.py
More file actions
65 lines (47 loc) · 1.96 KB
/
ex1.6.py
File metadata and controls
65 lines (47 loc) · 1.96 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 22 15:11:35 2019
@author: astro
"""
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
f1=str('time_BHillustris1_30.dat')
x=np.genfromtxt(f1,comments="#",dtype="float",usecols=(6),unpack=True)
y=np.genfromtxt(f1,comments="#",dtype="float", usecols=(7), unpack=True)
#reads only columns 7 and 8
for k in range(len(x)):
if (y[k]>x[k]):
y[k], x[k] = x[k], y[k]
#if the 1st column is smaller then change values with the other one
N= 50
m1 = np.linspace(min(x), max(x), num=N) #linspace for creating numeric sequences.(start,stop,num_range)
dm1 = m1[1] - m1[0] #see above max-min
m2 = np.linspace(min(y), max(y), num=N) #linspace for creating numeric sequences.(start,stop,num_range)
dm2 = m2[1] - m2[0] #see above max - min
z = np.zeros((N, N)) #array.
for bh1, bh2 in zip(np.array(x) - min(x), np.array(y)- min(y)): #for loop with two variable (x,y )
i = int(bh1/dm1)
j = int(bh2/dm2)
z[i,j]+=1
for i in range(N):
for j in range(N):
if(z[i,j]<=0.0):
z[i,j]=0.1
z[i,j]=np.log10(z[i,j]) # transforms z to log scale
cs=plt.contourf(m1, m2, z, 30, cmap=cm.viridis)
"""
# The last letter 'f' stands for 'filled' while plt.contour produces unfilled contour lines
z: a two dimensional array-like object of size n × m. The values over which the contour is drawn.
m1 and m2 represent the coordinates of the values in z. m1 and m2 must both be 2D arrays with the same shape as z
cmap: string. Sets the color map.
"""
# set color bar
cbar=plt.colorbar(cs,orientation='vertical')
#plt.colorbar, which is needed to generate a color bar for the contour plot.
cbar.set_label('N(merg)', rotation=90)
cbar.solids.set_edgecolor("face")
plt.xlabel('m\N{SUBSCRIPT ONE}[$M_\odot$]', fontsize=15)
plt.ylabel('m\N{SUBSCRIPT TWO}[$M_\odot$]', fontsize=15)
plt.show()