コード例 #1
0
ファイル: CDST_demo.py プロジェクト: MrKriss/CDST-demo
  def plot_dat(self, anomaly, data, standardise = 1):
    """ For a given detected anomaly, plots the data around that time point """

    # Need to add input checks 

    sample_half = int(round( self.p['zt_sample_size']/2.)) 
    dat = data[anomaly-sample_half:anomaly+sample_half,:]
    
    if standardise:
      fig = plt.figure()
      ax = fig.add_subplot(111)
      ax.plot(zscore(dat))
      bpList = bp_lookup(self.p['SAX_alphabet_size'])
      for bp in bpList:
        ax.axhline(y=bp, xmin=0, xmax=dat.shape[0], ls = '--', color = 'k')
        
      adjust_spines(ax, ['bottom'])
      
      ax.set_yticklabels([])
      ax.yaxis.set_ticks([])
      ax.set_xticklabels(range(anomaly-sample_half,anomaly+sample_half+1))
      for tick in ax.xaxis.get_major_ticks():
                      tick.label.set_fontsize(18)       
      
      
    else: 
      plt.figure()
      plt.plot(dat)
      bpList = bp_lookup(self.p['SAX_alphabet_size'])
      plt.hlines(bpList, xmin=0, xmax=dat.shape[0]-1, linestyles = 'dashed', color = 'k')           
コード例 #2
0
ファイル: SAX.py プロジェクト: MrKriss/CDST-demo
def plot_EgSAX(data, segMeans, alphaSize, compRatio):
  
  from matplotlib.ticker import NullFormatter
  from plot_utils import adjust_spines
  
  # Stored originally as wordSize x numStreams. Becaule plot func plots columsn by default 
  
  if segMeans.ndim == 1:
    numStreams = 1
    segMeans = np.atleast_2d(segMeans).T
  else:
    numStreams = segMeans.shape[1]
  wordSize = segMeans.shape[0]
  bpList = bp_lookup(alphaSize)  
  
  PAAStreams = np.zeros((wordSize*compRatio, numStreams)) 
  
  for stream in xrange(numStreams):
    temp = []
    for mean in segMeans[:,stream]: 
      temp.extend([mean]*int(compRatio)) 
    
    PAAStreams[:,stream] = np.array(temp)
  
  # Multiple Ploting 
  nullfmt   = NullFormatter()         # no labels
  
  # start with a rectangular Figure
  plt.figure()  
  # Plot Gaussina Axes (l,b r,t)
  axGauss = plt.axes([0.05,0.1, 0.2, 0.85]) 
  adjust_spines(axGauss, [])  
  # Plot Sax Axes
  axSAX = plt.axes([0.3,0.1, 0.65, 0.85], )
  
  # no labels
  #axSAX.xaxis.set_major_formatter(nullfmt)
  axGauss.yaxis.set_major_formatter(nullfmt)
  axGauss.yaxis.set_minor_formatter(nullfmt)
  
  # the SAX plot:
  axSAX.plot(PAAStreams, drawstyle = 'steps', color = 'r', lw = 1.5)
  for bp in bpList:
    axSAX.axhline(y=bp, xmin=0, xmax=PAAStreams.shape[0], ls = '--', color = 'k')
  axSAX.plot(data, color = 'b', lw = 1)
  
  # the Gaussian plot
  y = np.linspace(-3, 3, 1000)
  gauss_data = gauss_dist.pdf(y)
  axGauss.plot(-gauss_data, y)

  for bp in bpList:
      axGauss.axhline(y=bp, xmin=0, xmax=PAAStreams.shape[0], ls = '--', color = 'k')  

  # Tweek Axis
  axSAX.set_ylim( axGauss.get_ylim() )
  #axGauss.set_xlim( 0, -0.5 )
  adjust_spines(axGauss, [])
  adjust_spines(axSAX, ['left', 'bottom'])
  plt.xlabel('Time Steps')
  
  
  plt.show()  
  
  return PAAStreams
コード例 #3
0
                       })

## Turn off one axis to display accordingly to the other figure in example_4_synrel.py
ax[0].axis('off')

ax[1].errorbar(f_vals / Hz,
               np.mean(syn_mon.r_S[2 * N_synapses:], axis=1),
               np.std(syn_mon.r_S[2 * N_synapses:], axis=1),
               fmt='o',
               color='black',
               lw=0.5)
ax[1].set(xlim=(0.08, 100),
          xscale='log',
          ylim=(0., 0.7),
          ylabel=r'$\langle r_S \rangle$')
pu.adjust_spines(ax[1], ['left'])

ax[2].errorbar(f_vals / Hz,
               np.mean(syn_mon.r_S[N_synapses:2 * N_synapses], axis=1),
               np.std(syn_mon.r_S[N_synapses:2 * N_synapses], axis=1),
               fmt='o',
               color='C2',
               lw=0.5)
ax[2].set(xlim=(0.08, 100),
          xscale='log',
          ylim=(0., 0.2),
          ylabel=r'$\langle r_S \rangle$')
pu.adjust_spines(ax[2], ['left'])

ax[3].errorbar(f_vals / Hz,
               np.mean(syn_mon.r_S[:N_synapses], axis=1),
コード例 #4
0
           ast_mon.C[0] / umolar,
           '-',
           color='C2')
ax[0].plot((ast_mon.t - transient) / second,
           ast_mon.C[1] / umolar,
           '-',
           color='C3')
## Add threshold for gliotransmitter release
ax[0].plot(np.asarray([-transient / second, 0.0]),
           np.asarray([C_Theta, C_Theta]) / umolar,
           ':',
           color='gray')
ax[0].set(xlim=[-transient / second, 0.0],
          yticks=[0., 0.4, 0.8, 1.2],
          ylabel=r'$C$ ($\mu$M)')
pu.adjust_spines(ax[0], ['left'])

## Gliotransmitter concentration in the extracellular space
ax[1].plot((ast_mon.t - transient) / second,
           ast_mon.G_A[0] / umolar,
           '-',
           color='C2')
ax[1].plot((ast_mon.t - transient) / second,
           ast_mon.G_A[1] / umolar,
           '-',
           color='C3')
ax[1].set(yticks=[0., 50., 100.],
          xlim=[-transient / second, 0.0],
          xlabel='time (s)',
          ylabel=r'$G_A$ ($\mu$M)')
pu.adjust_spines(ax[1], ['left', 'bottom'])
コード例 #5
0
################################################################################
run(duration, report='text')

################################################################################
# Analysis and plotting
################################################################################
plt.style.use('figures.mplstyle')

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(6.26894, 6.26894 * 0.66),
                       gridspec_kw={'left': 0.1, 'bottom': 0.12})
scaling = 1.2
step = 10
ax.plot(astro_mon.t/second,
        (astro_mon.C[0:N_astro//2-1].T/astro_mon.C.max() +
         np.arange(N_astro//2-1)*scaling), color='black')
ax.plot(astro_mon.t/second, (astro_mon.C[N_astro//2:].T/astro_mon.C.max() +
                             np.arange(N_astro//2, N_astro)*scaling),
        color='black')
ax.plot(astro_mon.t/second, (astro_mon.C[N_astro//2-1].T/astro_mon.C.max() +
                             np.arange(N_astro//2-1, N_astro//2)*scaling),
        color='C0')
ax.set(xlim=(0., duration/second), ylim=(0, (N_astro+1.5)*scaling),
       xticks=np.arange(0., duration/second, 500), xlabel='time (s)',
       yticks=np.arange(0.5*scaling, (N_astro + 1.5)*scaling, step*scaling),
       yticklabels=[str(yt) for yt in np.arange(0, N_astro + 1, step)],
       ylabel='$C/C_{max}$ (cell index)')
pu.adjust_spines(ax, ['left', 'bottom'])

pu.adjust_ylabels([ax], x_offset=-0.08)

plt.show()
コード例 #6
0
ファイル: example_4_rsmean.py プロジェクト: brian-team/brian2
fig, ax = plt.subplots(nrows=4, ncols=1, figsize=(3.07, 3.07*1.33), sharex=False,
                       gridspec_kw={'height_ratios': [1, 3, 3, 3],
                                    'top': 0.98, 'bottom': 0.12,
                                    'left': 0.22, 'right': 0.93})

## Turn off one axis to display accordingly to the other figure in example_4_synrel.py
ax[0].axis('off')

ax[1].errorbar(f_vals/Hz, np.mean(syn_mon.r_S[2*N_synapses:], axis=1),
               np.std(syn_mon.r_S[2*N_synapses:], axis=1),
               fmt='o', color='black', lw=0.5)
ax[1].set(xlim=(0.08, 100), xscale='log',
          ylim=(0., 0.7),
          ylabel=r'$\langle r_S \rangle$')
pu.adjust_spines(ax[1], ['left'])

ax[2].errorbar(f_vals/Hz, np.mean(syn_mon.r_S[N_synapses:2*N_synapses], axis=1),
               np.std(syn_mon.r_S[N_synapses:2*N_synapses], axis=1),
               fmt='o', color='C2', lw=0.5)
ax[2].set(xlim=(0.08, 100), xscale='log',
          ylim=(0., 0.2), ylabel=r'$\langle r_S \rangle$')
pu.adjust_spines(ax[2], ['left'])

ax[3].errorbar(f_vals/Hz, np.mean(syn_mon.r_S[:N_synapses], axis=1),
               np.std(syn_mon.r_S[:N_synapses], axis=1),
               fmt='o', color='C3', lw=0.5)
ax[3].set(xlim=(0.08, 100), xticks=np.logspace(-1, 2, 4), xscale='log',
          ylim=(0., 0.7), xlabel='input frequency (Hz)',
          ylabel=r'$\langle r_S \rangle$')
ax[3].xaxis.set_major_formatter(ScalarFormatter())
コード例 #7
0
ファイル: SPIRIT_faulty.py プロジェクト: MrKriss/Old-PhD-Code
 # Plot data 
 fig = plt.figure()
 ax1 = fig.add_subplot(311)
 ax1.plot(res_sp['RSRE'])
 #plt.grid(True)
 
 ax2 = fig.add_subplot(312, sharex = ax1)
 ax2.plot(res_sp['e_ratio'])
 #plt.grid(True)
 
 ax3 = fig.add_subplot(313, sharex = ax1)
 ax3.plot(res_sp['orthog_error'])
 #plt.grid(True)
 
 # Shift spines
 adjust_spines(ax1, ['left', 'bottom'])
 adjust_spines(ax2, ['left', 'bottom'])        
 adjust_spines(ax3, ['left', 'bottom'])
 
 adjust_ticks(ax1, 'y', 5)
 adjust_ticks(ax2, 'y', 5)
 adjust_ticks(ax3, 'y', 5)
                 
 # Axis Labels
 plt.suptitle('Error Analysis of SPIRIT', size = 18, verticalalignment = 'top' )
 
 ylabx = -0.1        
 ax1.set_ylabel('RSRE', horizontalalignment = 'right', transform = ax1.transAxes )
 ax1.yaxis.set_label_coords(ylabx, 0.5)
 ax2.set_ylabel('Energy Ratio', horizontalalignment = 'right')
 ax2.yaxis.set_label_coords(ylabx, 0.5)
コード例 #8
0
ファイル: plot script2.py プロジェクト: aanchan/Old-PhD-Code
ax2 = fig.add_subplot(412, sharex=ax1)
ax2.plot(data['hidden'])
#plt.grid(True)

ax3 = fig.add_subplot(413, sharex=ax1)
ax3.plot(data['e_ratio'])
#plt.grid(True)
plt.axhline(y=e_high, ls='--')
plt.axhline(y=e_low, ls='--')

ax4 = fig.add_subplot(414, sharex=ax1)
ax4.plot(data['orthog_error'])

# Shift spines
adjust_spines(ax1, ['left', 'bottom'])
adjust_spines(ax2, ['left', 'bottom'])
adjust_spines(ax3, ['left', 'bottom'])
adjust_spines(ax4, ['left', 'bottom'])

adjust_ticks(ax1, 'y', 5)
adjust_ticks(ax2, 'y', 5)
adjust_ticks(ax3, 'y', 5)
adjust_ticks(ax4, 'y', 5)

ax1.set_xlim([0, streams.shape[0]])

# Axis Labels
plt.suptitle('Error Analysis of SPIRIT', size=18, verticalalignment='top')

ylabx = -0.13
コード例 #9
0
################################################################################
run(duration, report='text')

################################################################################
# Analysis and plotting
################################################################################
plt.style.use('figures.mplstyle')

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(6.26894, 6.26894 * 0.66),
                       gridspec_kw={'left': 0.1, 'bottom': 0.12})
scaling = 1.2
step = 10
ax.plot(astro_mon.t/second,
        (astro_mon.C[0:N_astro//2-1].T/astro_mon.C.max() +
         np.arange(N_astro//2-1)*scaling), color='black')
ax.plot(astro_mon.t/second, (astro_mon.C[N_astro//2:].T/astro_mon.C.max() +
                             np.arange(N_astro//2, N_astro)*scaling),
        color='black')
ax.plot(astro_mon.t/second, (astro_mon.C[N_astro//2-1].T/astro_mon.C.max() +
                             np.arange(N_astro//2-1, N_astro//2)*scaling),
        color='C0')
ax.set(xlim=(0., duration/second), ylim=(0, (N_astro+1.5)*scaling),
       xticks=np.arange(0., duration/second, 500), xlabel='time (s)',
       yticks=np.arange(0.5*scaling, (N_astro + 1.5)*scaling, step*scaling),
       yticklabels=[str(yt) for yt in np.arange(0, N_astro + 1, step)],
       ylabel='$C/C_{max}$ (cell index)')
pu.adjust_spines(ax, ['left', 'bottom'])

pu.adjust_ylabels([ax], x_offset=-0.08)

plt.show()