import numpy as np
import matplotlib.pyplot as plt
import itertools
%matplotlib inline
from math import sqrt
fig_width_pt = 246.0  # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27               # Convert pt to inches
golden_mean = (sqrt(5)-1.0)/2.0         # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt  # width in inches
fig_height =fig_width*golden_mean       # height in inches
fig_size = [fig_width,fig_height]
data = np.load('../ns-res-bayes-dir-10.0.npy')
nx, ny = (500, 100)
dist_m = np.linspace(0, 1, nx)
velo_m = np.linspace(0.1, 1.5, ny)*-1000
clist = [u'#E24A33', u'#348ABD', u'#988ED5', u'#777777', u'#FBC15E', 
         u'#8EBA42', u'#313695', u'#FFB5B8', u'#bf812d', u'#01665e']
cgen = itertools.cycle(clist)
plt.style.use('/home/daniel/repositories/burst-style/burst.mplstyle')
plt.contour(dist_m, -velo_m, data.T*1e9, color=cgen.next(), levels=[100])
 /home/daniel/.virtualenvs/argus/local/lib/python2.7/site-packages/matplotlib/__init__.py:1076: UserWarning: Bad val "True," on line #7
	"text.usetex: True,
"
	in file "/home/daniel/repositories/burst-style/burst.mplstyle"
	Key text.usetex: Could not convert "true," to boolean
  (val, error_details, msg))
/home/daniel/.virtualenvs/argus/local/lib/python2.7/site-packages/matplotlib/__init__.py:1076: UserWarning: Bad val "black," on line #9
	"text.color          : black,
"
	in file "/home/daniel/repositories/burst-style/burst.mplstyle"
	Key text.color: black, does not look like a color arg
Color tuples must be length 3
  (val, error_details, msg))

<matplotlib.contour.QuadContourSet at 0x7f52fd40d750>
 /home/daniel/.virtualenvs/argus/local/lib/python2.7/site-packages/matplotlib/font_manager.py:1288: UserWarning: findfont: Font family [u"'New Century Schoolbook'"] not found. Falling back to Bitstream Vera Sans
  (prop.get_family(), self.defaultFamily[fontext]))

png
years_max = 100

newx = np.linspace(0, 1, 200);
import matplotlib.patheffects as path_effects
dat1 = {}
lines1 = {}

for i in xrange(years_max/10):
    #dat1[i] = np.load('/home/daniel/repositories/argus/ns-res-bayes-dir-{}.0.npy'.format((i+1)*10))
    dat1[i] = np.load('/home/daniel/repositories/argus/scripts/ns-res-bayes-dir-{:.1f}-8e-08ns.npy'.format((i+1)*10))
for i in xrange(years_max/10):
    nx, ny = (500, 200)
    dist_m = np.linspace(0, 1, nx)
    velo_m = np.linspace(0.1, 1.5, ny)*-1000

    levels=[1, 10,50, 100, 150, 1000]
    CS = plt.contour(dist_m, -velo_m, dat1[i].T*1e9, levels=levels, colors='k');
    plt.clabel(CS, fmt='%1.0f ns',
                   fontsize=12, colors='k');
    plt.title('After {} years'.format((i+1)*10));
    lines1[i]= np.array(CS.allsegs)
    plt.clf();
<matplotlib.figure.Figure at 0x7fd235098c50>
plt.rcParams["font.family"] = "Times New Roman"

fig_width, fig_height = 4, 3
figure, ax = plt.subplots(figsize=(2*fig_width, 2*fig_height));#figsize=(13,5));

ax.set_xlim([0.0,1.0]);
ax.set_ylim([100,1500]);
#plt.title('Observation times required to rule out the presence of a neutron star, using an evidence-based method.');
#
clist = [u'#E24A33', u'#348ABD', u'#988ED5', u'#777777', u'#FBC15E', u'#8EBA42', u'#313695', u'#FFB5B8', u'#bf812d', u'#01665e']#rcParams['axes.color_cycle']
cgen = itertools.cycle(clist)
bottom = yaxis = np.ones(200)*1000#np.nan
newx = np.linspace(0, 1, 200)
for i in range(years_max/10):
    col = cgen.next()
    ux = lines1[i][4][0][:,0]
    uy = lines1[i][4][0][:,1]
    uz = np.polyfit(ux, uy, 2)
    line = np.poly1d(uz)
    ax.plot(newx, line(newx),  lw=2, color=col, zorder=10,label='%s y'%(10+10*i));
    text = ax.text(lines1[i][4][0][:,0][200], lines1[i][4][0][:,1][200], '%s'%(10+10*i), 
            size='large', ha='center', va='center', zorder=100)

    text.set_path_effects([path_effects.Stroke(linewidth=3, foreground='white'),
                       path_effects.Normal()])
    
cgen = itertools.cycle(clist)
col = cgen.next()
yaxis = np.ones(len(newx))*1e5
ux = lines1[0][4][0][:,0]
uy = lines1[0][4][0][:,1]
uz = np.polyfit(ux, uy, 2)
up = np.poly1d(uz)
#upper = np.interp(newx, up(newx))
ax.fill_between(newx, yaxis, up(newx), interpolate=True, alpha=0.2, facecolor=col,zorder=1) 
for i in range(1,years_max/10):
    col = cgen.next()
    newx = np.linspace(0, 1, 2000);
    lx = lines1[i-1][4][0][:,0]
    ly = lines1[i-1][4][0][:,1]
    lz = np.polyfit(lx, ly, 2)
    lp = np.poly1d(uz)
    ux = lines1[i][4][0][:,0]
    uy = lines1[i][4][0][:,1]
    uz = np.polyfit(ux, uy, 2)
    up = np.poly1d(uz)
    #plt.plot(x,)
    #lower = np.interp(newx, lines1[i-1][4][0][:,0], lines1[i-1][4][0][:,1])
    #upper = np.interp(newx, lines1[i][4][0][:,0], lines1[i][4][0][:,1])
    ax.fill_between(newx, lp(newx), up(newx), interpolate=True, alpha=0.2, facecolor=col,zorder=1) 
    
new_tick_locations = dist_m*2.1
ax2 = ax.twiny()
ax2.set_xticks(np.linspace(0,2.1, 22))
ax2.grid(b=False)
ax2.xaxis.set_ticks_position("bottom")
ax2.xaxis.set_label_position("bottom")
ax2.spines["bottom"].set_position(("axes", -0.05))

new_tick_locations = dist_m*4.4
ax3 = ax.twiny()
ax3.set_xticks(np.linspace(0,4.4, 23))
ax3.grid(b=False)
ax3.xaxis.set_ticks_position("bottom")
ax3.xaxis.set_label_position("bottom")
ax3.spines["bottom"].set_position(("axes", -0.1))

#new_tick_locations = velo_m*0.655
ax4 = ax.twinx()
ax4.set_yticks([0, 35, 135, 235, 335, 435, 535, 590])
ax4.set_yticklabels(np.array([65, 100, 200, 300, 400, 500, 600, 655])*1.5)
ax4.grid(b=False)
ax4.yaxis.set_ticks_position("left")
ax4.yaxis.set_label_position("left")
ax4.spines["left"].set_position(("axes", -0.06))

ax3.set_xlabel('Initial distance to object [pc]');
ax4.set_ylabel('Initial object velocity [km/s]');

ax.annotate('1', (1,0), (12, -6), xycoords='axes fraction', 
            textcoords='offset points', va='center', color='#777777');
ax2.annotate('10', (1,0), (12, -24), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777');
ax3.annotate('100', (1,0), (12, -41), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777');
ax3.annotate(r'Object mass [${\rm M}_{\odot}$]', (1,0), (12, 38), 
             xycoords='axes fraction', textcoords='offset points', 
             va='center', rotation=90, color='#777777');
ax3.annotate('Pessimistic', (0,0), (-20, -28), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777',
            rotation=90);
ax3.annotate('Optimistic', (0,0), (-35, -28), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777',
            rotation=90);

plt.tight_layout();

plt.savefig('evidencemethod_new.pdf', bbox_inches='tight', dpi=300)
#plt.savefig('/home/daniel/repositories/gu-poster/figures/plot.pdf', bbox_inches='tight', dpi=300)
png
plt.imshow(dat1[i].T)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7fd200fddd10>
png
years_max = 20

newx = np.linspace(0, 1, 200);
import matplotlib.patheffects as path_effects
dat1 = {}
lines1 = {}

for i in xrange(0, years_max/10):
    #dat1[i] = np.load('/home/daniel/repositories/argus/ns-res-bayes-dir-{}.0.npy'.format((i+1)*10))
    dat1[i] = np.load('/home/daniel/repositories/argus/scripts/ns-res-poly-dir-{}.0-8e-08ns.npy'.format((i+1)*10))
for i in xrange(0,years_max/10):
    nx, ny = (100, 50)
    dist_m = np.linspace(0.1, 1, nx)
    velo_m = np.linspace(0, 1.5, ny)*-1000

    levels=[1, 10,50, 100, 150, 1000]
    CS = plt.contour(dist_m, -velo_m, dat1[i].T*1e9, levels=levels, colors='k');
    plt.clabel(CS, fmt='%1.0f ns',
                   fontsize=12, colors='k');
    plt.title('After {} years'.format((i+1)*10));
    lines1[i]= np.array(CS.allsegs)
    #plt.clf();
png
plt.imshow(dat1[0])
<matplotlib.image.AxesImage at 0x7fd201830d10>
png
plt.contourf(dist_m, -velo_m, dat1[1].T*1e9)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x7fd20188ffd0>
png
plt.rcParams["font.family"] = "Times New Roman"

fig_width, fig_height = 4, 3
figure, ax = plt.subplots(figsize=(2*fig_width, 2*fig_height));#figsize=(13,5));

ax.set_xlim([0.0,1.0]);
ax.set_ylim([100,1500]);
#plt.title('Observation times required to rule out the presence of a neutron star, using an evidence-based method.');
#
clist = [u'#E24A33', u'#348ABD', u'#988ED5', u'#777777', u'#FBC15E', u'#8EBA42', u'#313695', u'#FFB5B8', u'#bf812d', u'#01665e']#rcParams['axes.color_cycle']
cgen = itertools.cycle(clist)
bottom = yaxis = np.ones(200)*1000#np.nan
newx = np.linspace(0, 1, 50)
for i in range(1,years_max/10):
    col = cgen.next()
    ux = lines1[i][4][0][:,0]
    uy = lines1[i][4][0][:,1]
    uz = np.polyfit(ux, uy, 2)
    line = np.poly1d(uz)
    ax.plot(newx, line(newx),  lw=2, color=col, zorder=10,label='%s y'%(10+10*i));
    text = ax.text(lines1[i][4][0][:,0][200], lines1[i][4][0][:,1][200], '%s'%(10+10*i), 
            size='large', ha='center', va='center', zorder=100)

    text.set_path_effects([path_effects.Stroke(linewidth=3, foreground='white'),
                       path_effects.Normal()])
    
cgen = itertools.cycle(clist)
col = cgen.next()
yaxis = np.ones(len(newx))*1e5
ux = lines1[0][4][0][:,0]
uy = lines1[0][4][0][:,1]
uz = np.polyfit(ux, uy, 2)
up = np.poly1d(uz)
#upper = np.interp(newx, up(newx))
ax.fill_between(newx, yaxis, up(newx), interpolate=True, alpha=0.2, facecolor=col,zorder=1) 
for i in range(1,years_max/10):
    col = cgen.next()
    newx = np.linspace(0, 1, 2000);
    lx = lines1[i-1][4][0][:,0]
    ly = lines1[i-1][4][0][:,1]
    lz = np.polyfit(lx, ly, 2)
    lp = np.poly1d(uz)
    ux = lines1[i][4][0][:,0]
    uy = lines1[i][4][0][:,1]
    uz = np.polyfit(ux, uy, 2)
    up = np.poly1d(uz)
    #plt.plot(x,)
    #lower = np.interp(newx, lines1[i-1][4][0][:,0], lines1[i-1][4][0][:,1])
    #upper = np.interp(newx, lines1[i][4][0][:,0], lines1[i][4][0][:,1])
    ax.fill_between(newx, lp(newx), up(newx), interpolate=True, alpha=0.2, facecolor=col,zorder=1) 
    
new_tick_locations = dist_m*2.1
ax2 = ax.twiny()
ax2.set_xticks(np.linspace(0,2.1, 22))
ax2.grid(b=False)
ax2.xaxis.set_ticks_position("bottom")
ax2.xaxis.set_label_position("bottom")
ax2.spines["bottom"].set_position(("axes", -0.05))

new_tick_locations = dist_m*4.4
ax3 = ax.twiny()
ax3.set_xticks(np.linspace(0,4.4, 23))
ax3.grid(b=False)
ax3.xaxis.set_ticks_position("bottom")
ax3.xaxis.set_label_position("bottom")
ax3.spines["bottom"].set_position(("axes", -0.1))

#new_tick_locations = velo_m*0.655
ax4 = ax.twinx()
ax4.set_yticks([0, 35, 135, 235, 335, 435, 535, 590])
ax4.set_yticklabels(np.array([65, 100, 200, 300, 400, 500, 600, 655])*1.5)
ax4.grid(b=False)
ax4.yaxis.set_ticks_position("left")
ax4.yaxis.set_label_position("left")
ax4.spines["left"].set_position(("axes", -0.06))

ax3.set_xlabel('Initial distance to object [pc]');
ax4.set_ylabel('Initial object velocity [km/s]');

ax.annotate('1', (1,0), (12, -6), xycoords='axes fraction', 
            textcoords='offset points', va='center', color='#777777');
ax2.annotate('10', (1,0), (12, -24), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777');
ax3.annotate('100', (1,0), (12, -41), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777');
ax3.annotate(r'Object mass [${\rm M}_{\odot}$]', (1,0), (12, 38), 
             xycoords='axes fraction', textcoords='offset points', 
             va='center', rotation=90, color='#777777');
ax3.annotate('Pessimistic', (0,0), (-20, -28), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777',
            rotation=90);
ax3.annotate('Optimistic', (0,0), (-35, -28), xycoords='axes fraction', 
             textcoords='offset points', va='center', color='#777777',
            rotation=90);

plt.tight_layout();

#plt.savefig('evidencemethod_new.pdf', bbox_inches='tight', dpi=300)
#plt.savefig('/home/daniel/repositories/gu-poster/figures/plot.pdf', bbox_inches='tight', dpi=300)
---------------------------------------------------------------------------

IndexError                                Traceback (most recent call last)

<ipython-input-15-1aa5c946d566> in <module>()
     14 for i in range(1,years_max/10):
     15     col = cgen.next()
---> 16     ux = lines1[i][4][0][:,0]
     17     uy = lines1[i][4][0][:,1]
     18     uz = np.polyfit(ux, uy, 2)


IndexError: index 0 is out of bounds for axis 0 with size 0
png
coeffs = []
for i in range(10):
    x = lines1[i][4][0][:,0]
    y = lines1[i][4][0][:,1]
    z = np.polyfit(x, y, 2)
    p = np.poly1d(z)
    plt.plot(x, p(x))
    coeffs.append(z)
    #plt.plot(lines1[i][4][0][:,0], lines1[i][4][0][:,1])
png
plt.plot(np.log(np.array(coeffs)[:,0]))
[<matplotlib.lines.Line2D at 0x7fbaf34faad0>]
png
plt.plot(np.log(np.array(coeffs)[:,1]))
[<matplotlib.lines.Line2D at 0x7fbaf1019990>]
png
plt.plot(x,y)
[<matplotlib.lines.Line2D at 0x7fbaf6002f50>]
png
plt.plot(x, p(x))
[<matplotlib.lines.Line2D at 0x7fbaf6024c50>]
png