Beispiel #1
0
    def plot_model(self,
                   ax,
                   I0,
                   R,
                   b0,
                   a0,
                   model_kind=None,
                   dimless=True,
                   rdf=True,
                   bg=False):
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif', size=12)

        if ax is None:
            ax = plt.gca()

        if model_kind is None:
            model_kind = SprModelRadial._model_spr

        q0, qn = self.q[0, 0], self.q[-1, 0]
        q = np.linspace(q0, qn, 300).reshape(300, 1)
        q1 = np.linspace(0, q0, 50).reshape(50, 1)

        I = self.model_q(I0, R, q, model_kind) + a0 * np.interp(
            q, self.q.flat, self.b.flat) + b0
        I1 = self.model_q(I0, R, q1, model_kind) + a0 * self.b[0, 0] + b0
        #q = q.reshape(200,1)
        #print("I", I.shape)
        #print("q", q.shape)

        dq = (7.72525183693770716 - 4.49340945790906418) / (math.pi * R) / 9
        if dq < self.dq:
            dq = self.dq

        qr, v, sv, b, sb, nn = SprModelRadial._rdf(self.qi, dq, self.vi,
                                                   self.bi, self.si, self.ei)

        if dimless:
            q = q * R
            q1 = q1 * R
            qr = qr * R
            ax.set_xlabel("$q$")
        else:
            #q = self.q
            ax.set_xlabel("$q, \mathrm{\AA}^{-1}$")

        #idx = I > 0.
        ax.semilogy(q, I - b0, 'C0', linewidth=2)
        ax.semilogy(q1, I1 - b0, 'C0:', linewidth=2)
        if rdf:
            idx = v > 0.
            ax.semilogy(qr, v - b0, 'C1--', linewidth=2)
        if bg:
            idx = b > 0.
            ax.semilogy(qr, a0 * b, 'C2', linewidth=2)

        ax.set_xlim(0, q[-1])
        ax.set_ylabel("$I, \mathrm{photons}$")
Beispiel #2
0
def fxcor_subplot(result, GCs, stars):
        '''
        Makes subplot of TDR vs VERR and VREL.
        Returns a figure object
        '''
        plt.close('all')
        fig = plt.figure(figsize=(6,6))
        gs = gridspec.GridSpec(70,40,bottom=0.10,left=0.15,right=0.98, top = 0.95)

        plt.rc('text', usetex=True)
        plt.rc('font', family='serif')

        R_vel = plt.subplot(gs[10:40,0:40])
        R_err = plt.subplot(gs[40:70,0:40])
        R_hist = plt.subplot(gs[0:10,0:40])
        
        R_hist.axis('off')
        plt.setp(R_vel.get_xticklabels(), visible=False)
        
        x = result.TDR
        y = result.VREL_helio
        R_vel.scatter(x, y, s=10, c='gray', edgecolor='none', alpha = 0.6, label = 'All')

        x = GCs.TDR
        y = GCs.VREL_helio
        R_vel.scatter(x, y, s=11, c='orange', edgecolor='none', alpha = 0.8, label = 'GCs')

        x = stars.TDR
        y = stars.VREL_helio
        R_vel.scatter(x, y, s=11, c='green', edgecolor='none', alpha = 0.8, label = 'Stars')

        R_vel.set_xlim(1,20)
        R_vel.set_ylim(-2000,5000)
        R_vel.set_ylabel(r'$v$ $[km \, s^{-1}]$')
        plt.setp(R_vel.get_yticklabels()[0], visible=False)  
        
        x = result.TDR
        y = result.VERR
        R_err.scatter(x, y,s=10, c='gray', edgecolor='none', alpha = 0.6)

        x = GCs.TDR
        y = GCs.VERR
        R_err.scatter(x, y,s=11, c='orange', edgecolor='none', alpha = 0.8)

        x = stars.TDR
        y = stars.VERR
        R_err.scatter(x, y,s=11, c='green', edgecolor='none', alpha = 0.8)

        R_err.set_ylim(2,80)
        R_err.set_xlim(1,20)
        R_err.set_ylabel(r'$\delta v$ $[km \, s^{-1}]$')
        R_err.set_xlabel(r'TDR')
        plt.setp(R_err.get_yticklabels()[-1], visible=False)
        R_vel.legend()
        
        R_hist.hist([GCs.TDR,stars.TDR], range = (1,20), bins = 50, normed=True,
                                 color=['orange','green'])
        return fig
Beispiel #3
0
    def plot_rdf(self, ax, R=None):
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif', size=12)

        if ax is None:
            ax = plt.gca()

        idx = self.v > 0.
        if R is None:
            ax.loglog(self.q[idx], self.v[idx])
            ax.loglog(self.q[idx], self.v[idx] + self.sv[idx] + self.sb[idx])
            ax.set_xlabel("$q, \mathrm{\AA}^{-1}$")
        else:
            ax.loglog(self.q[idx] * R, self.v[idx])
            ax.loglog(self.q[idx], self.v[idx] + self.sv[idx] + self.sb[idx])
            ax.set_xlabel("$q$")

        ax.set_ylabel("$I, \mathrm{photon}/\mathrm{\AA}^{-2}$")
Beispiel #4
0
def plot_piledspectra():
    fig = plt.figure(figsize = (6,8)) 
    plt.xlim(5000,9000)
    
    specindex = range(0,100,10)
    offset = np.arange(0,len(specindex)) * 0.5
    ylim = [0.5, offset[-1] + 1.3]
    plt.ylim(ylim[0], ylim[1])
    
    plt.rc('text', usetex=True)
    plt.rc('font', family='serif')
    
    plt.xlabel(r'Restrame Wavelength [ \AA\ ]')
    plt.ylabel(r'Flux')
    
    line_wave = [5175., 5892., 6562.8, 8498., 8542., 8662.] 
        #       ['Mgb', 'NaD', 'Halpha', 'CaT', 'CaT', 'CaT']
    for line in line_wave:
            x = [line, line]
            y = [ylim[0], ylim[1]]
            plt.plot(x, y, c= 'gray', linewidth=1.0)
    
    plt.annotate(r'CaT', xy=(8540.0, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'H$\alpha$', xy=(6562.8, ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'NaD', xy=(5892., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    plt.annotate(r'Mg$\beta$', xy=(5175., ylim[1] + 0.05), xycoords='data', annotation_clip=False)
    
    for i,j in zip(specindex,offset):
        iraf.noao.onedspec.continuum(input = GCssorted.ORIGINALFILE.iloc[i] + '[1]', output = '/Volumes/VINCE/OAC/continuum.fits',
            type = 'ratio', naverage = '3', function = 'spline3',
            order = '5', low_reject = '2.0', high_reject = '2.0', niterate = '10')
    
        data = fits.getdata('/Volumes/VINCE/OAC/continuum.fits', 0)
        
        hdu = fits.open(GCssorted.ORIGINALFILE.iloc[i])
        header1 = hdu[1].header
        lamRange = header1['CRVAL1']  + np.array([0., header1['CD1_1'] * (header1['NAXIS1'] - 1)]) 
        wavelength = np.linspace(lamRange[0],lamRange[1], header1['NAXIS1'])
        hdu.close()
    
        zp = 1. + (GCssorted.VREL.iloc[i] / 299792.458)
      
        plt.plot(wavelength/zp, gaussian_filter(data,2) + j, c = 'black', lw=1)
        os.remove('/Volumes/VINCE/OAC/continuum.fits')
Beispiel #5
0
# -*- coding:utf-8 -*-
#V:Python 3.6.3
import pandas as pd
from IPython.display import display
from matplotlib.pylab import plt

data = pd.read_csv('house3.csv')
data['total_price'] = data['price'] * data['area'] / 10000

data_mean = data.groupby('district')['price'].mean()
data_count = data.groupby('district')['price'].count()

#柱状图分析各区的二手房的房价
plt.figure(figsize=(10, 6))
plt.rc('font', family='SimHei', size=13)
plt.title(u'各区域的平均二手房房价')
plt.xlabel(u'南京城区')
plt.ylabel(u'平均房价')
plt.bar(data_mean.index, data_count.values, color='g')
plt.show()

plt.figure(figsize=(10, 10))
plt.rc('font', family='SimHei', size=13)
explode = [0] * len(data_count)
explode[9] = 0.1
plt.pie(data_count,
        radius=2,
        autopct='%1.f%%',
        shadow=True,
        labels=data_mean.index,
        explode=explode)
Beispiel #6
0
print('\n-------공분산 출력 -------')
print(np.cov(data.친밀도, data.적절성))
print(np.cov(data.친밀도, data.만족도))
print('\ncov:\n', data.cov())

print('\n-------상관계수 출력 -------')
print(np.corrcoef(data.친밀도, data.적절성))
print('\ncorr:\n', data.corr())
print('\ncorr-pearson:\n', data.corr(method='pearson'))  # 변수가 등간 또는 비율척도
print('\ncorr-spearman:\n', data.corr(method='spearman'))  # 변수가 서열척도
print('\ncorr-kendall:\n', data.corr(method='kendall'))  # spearman만 유사

# 상관계수를 방향성 있는 색으로 시각화 (heatmap)
import seaborn as sns
plt.rc('font', family='malgun gothic')
sns.heatmap(data.corr())
plt.show()

# hitmap에 텍스트 표시 추가사항 적용해 보기
corr = data.corr()
# Generate a mask for the upper triangle
mask = np.zeros_like(corr, dtype=np.bool)  # 상관계수값 표시
mask[np.triu_indices_from(mask)] = True
# Draw the heatmap with the mask and correct aspect ratio
vmax = np.abs(corr.values[~mask]).max()
fig, ax = plt.subplots()  # Set up the matplotlib figure

sns.heatmap(corr,
            mask=mask,
            vmin=-vmax,
index, dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop=True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop=True)
print len(BergondMatch)

x = VIMOS['VREL_helio']
xerr = VIMOS['VERR']
y = BergondMatch['HRV']
yerr = BergondMatch['e_HRV']

plt.errorbar(x,
             y,
             yerr=yerr,
             xerr=xerr,
             fmt='o',
             c='red',
             label='Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc='upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x - y)
BergondGCs = Bergond[Bergond['Type'] =='gc']
BergondGCs[['RAJ2000', 'DEJ2000']].to_csv('/Volumes/VINCE/OAC/imaging/BergondGCs_RADEC.reg', index = False, sep =' ', header = None)

cat1 = coords.SkyCoord(GCs['RA_g'], GCs['DEC_g'], unit=(u.degree, u.degree))
cat2 = coords.SkyCoord(BergondGCs['RAJ2000'], BergondGCs['DEJ2000'], unit=(u.degree, u.degree))

index,dist2d, _ = cat1.match_to_catalog_sky(cat2)
mask = dist2d.arcsec < 0.3
new_idx = index[mask]

VIMOS = GCs.ix[mask].reset_index(drop = True)
BergondMatch = BergondGCs.ix[new_idx].reset_index(drop = True)
print len(BergondMatch)

x = VIMOS['VREL_helio'] 
xerr = VIMOS['VERR'] 
y = BergondMatch['HRV'] 
yerr = BergondMatch['e_HRV'] 

plt.errorbar(x, y, yerr= yerr, xerr = xerr, fmt = 'o', c ='red',label = 'Bergond et al.')

plt.rc('text', usetex=True)
plt.rc('font', family='serif')    
plt.xlabel(r'Velocity from this work [km s$^-1$ ]')
plt.ylabel(r'Velocity from the literature [km s$^-1$ ]')
plt.legend(loc = 'upper left')
plt.tight_layout()
plt.show()

print 'rms (VIMOS - Bergond) GCs = ', np.std(x-y)