In [1]:
period = [2.4, 5, 6.3, 4.1]
print(60 * period)
bh_mass = [4.3, 5.8, 9.5, 7.6]
MASS_SUN = 1.99 * 10 ** 30
print(MASS_SUN * bh_mass)
In [2]:
time = list(range(1,10, 0.1))
In [3]:
import numpy as np
In [4]:
period = np.array([2.4, 5, 6.3, 4.1])
print(60 * period)
bh_mass = np.array([4.3, 5.8, 9.5, 7.6])
MASS_SUN = 1.99 * 10 ** 30
print(MASS_SUN * bh_mass)
In [5]:
time = np.arange(1, 10, 0.1)
time2 = np.linspace(1, 10, 5)
init_value = np.zeros(10)
init_value2= np.ones(10)
print(time)
print(time2)
print(init_value)
print(init_value2)
In [6]:
period2 = np.array([[2.4, 5, 6.3, 4.1], [4.2, 5.3, 1.2, 7.1]])
print(period2.ndim)
print(period2.shape)
print(period2.dtype)
In [7]:
print(period2[0])
print(period2[1][1:-1])
In [8]:
print(np.sort(period2[0]))
print(np.argsort(period2[0]))
print(np.argmax(period2[0]))
print(np.where(period2[0] > 4.5))
print(np.extract(period2[0] > 4.5, period2[0]))
In [9]:
counts = 100 * np.sin(2 * np.pi * 1. / period2[0][1] * time) + 500
print(counts)
In [10]:
import numpy.random as npr
print(npr.rand(5))
print(npr.randn(10))
print(npr.normal(5., 1., 10))
In [11]:
lc = np.array([time, counts])
np.savetxt('test.out', lc)
input_time, input_counts = np.loadtxt('test.out')
In [12]:
print(input_time)
print(input_counts)
In [13]:
import matplotlib.pyplot as plt
%matplotlib inline
In [14]:
plt.plot(input_time, input_counts)
plt.xlabel('Time')
plt.ylabel('Counts')
plt.title('Light curve', fontsize=18)
plt.axis([1, 15, 350, 700])
plt.xticks([1, 5, 10])
plt.yticks([350, 500, 700])
#plt.show() # 開啟圖片編輯視窗,並將圖顯示在該視窗中,透過該視窗可修改圖片、存檔
In [15]:
#plt.hold(True) # 保留目前的圖,以便重疊繪圖
plt.plot(input_time, input_counts-100, marker='o', color='green', linewidth=1)
In [16]:
plt.plot(input_time, input_counts+100, 'r*')
#plt.legend(('lc1', 'lc2', 'lc3'))
#plt.hold(False)
In [17]:
plt.subplot(211)
plt.plot(input_time, input_counts)
plt.subplot(212)
plt.plot(input_time, input_counts, '.m')
#plt.savefig('subplot.png')
In [18]:
y_errors = 10 * npr.rand(len(input_time)) + 5
plt.plot(input_time, input_counts, 'k.')
plt.errorbar(input_time, input_counts, yerr=y_errors, fmt='r')