Python pylab.rc() Examples
The following are 7
code examples of pylab.rc().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pylab
, or try the search function
.
Example #1
Source File: plot.py From TOPFARM with GNU Affero General Public License v3.0 | 6 votes |
def __init__(self, add_inputs, title='', **kwargs): super(OffshorePlot, self).__init__(**kwargs) self.fig = plt.figure(num=None, facecolor='w', edgecolor='k') #figsize=(13, 8), dpi=1000 self.shape_plot = self.fig.add_subplot(121) self.objf_plot = self.fig.add_subplot(122) self.targname = add_inputs self.title = title # Adding automatically the inputs for i in add_inputs: self.add(i, Float(0.0, iotype='in')) #sns.set(style="darkgrid") #self.pal = sns.dark_palette("skyblue", as_cmap=True) plt.rc('lines', linewidth=1) plt.ion() self.force_execute = True if not pa('fig').exists(): pa('fig').mkdir()
Example #2
Source File: analyser.py From spotpy with MIT License | 5 votes |
def plot_parametertrace_algorithms(result_lists, algorithmnames, spot_setup, fig_name='parametertrace_algorithms.png'): """Example Plot as seen in the SPOTPY Documentation""" import matplotlib.pyplot as plt font = {'family' : 'calibri', 'weight' : 'normal', 'size' : 20} plt.rc('font', **font) fig=plt.figure(figsize=(17,5)) subplots=len(result_lists) parameter = spotpy.parameter.get_parameters_array(spot_setup) rows=len(parameter['name']) for j in range(rows): for i in range(subplots): ax = plt.subplot(rows,subplots,i+1+j*subplots) data=result_lists[i]['par'+parameter['name'][j]] ax.plot(data,'b-') if i==0: ax.set_ylabel(parameter['name'][j]) rep = len(data) if i>0: ax.yaxis.set_ticks([]) if j==rows-1: ax.set_xlabel(algorithmnames[i-subplots]) else: ax.xaxis.set_ticks([]) ax.plot([1]*rep,'r--') ax.set_xlim(0,rep) ax.set_ylim(parameter['minbound'][j],parameter['maxbound'][j]) #plt.tight_layout() fig.savefig(fig_name, bbox_inches='tight')
Example #3
Source File: analyser.py From spotpy with MIT License | 5 votes |
def plot_objectivefunctiontraces(results,evaluation,algorithms,fig_name='Like_trace.png'): import matplotlib.pyplot as plt from matplotlib import colors cnames=list(colors.cnames) font = {'family' : 'calibri', 'weight' : 'normal', 'size' : 20} plt.rc('font', **font) fig=plt.figure(figsize=(16,3)) xticks=[5000,15000] for i in range(len(results)): ax = plt.subplot(1,len(results),i+1) likes=calc_like(results[i],evaluation,spotpy.objectivefunctions.rmse) ax.plot(likes,'b-') ax.set_ylim(0,25) ax.set_xlim(0,len(results[0])) ax.set_xlabel(algorithms[i]) ax.xaxis.set_ticks(xticks) if i==0: ax.set_ylabel('RMSE') ax.yaxis.set_ticks([0,10,20]) else: ax.yaxis.set_ticks([]) plt.tight_layout() fig.savefig(fig_name)
Example #4
Source File: covc_encdec.py From seq2seq-keyphrase with MIT License | 4 votes |
def analyse_(self, inputs, outputs, idx2word, inputs_unk=None, return_attend=False, name=None, display=False): def cut_zero(sample, idx2word, ppp=None, Lmax=None): if Lmax is None: Lmax = self.config['dec_voc_size'] if ppp is None: if 0 not in sample: return ['{}'.format(idx2word[w].encode('utf-8')) if w < Lmax else '{}'.format(idx2word[inputs[w - Lmax]].encode('utf-8')) for w in sample] return ['{}'.format(idx2word[w].encode('utf-8')) if w < Lmax else '{}'.format(idx2word[inputs[w - Lmax]].encode('utf-8')) for w in sample[:sample.index(0)]] else: if 0 not in sample: return ['{0} ({1:1.1f})'.format( idx2word[w].encode('utf-8'), p) if w < Lmax else '{0} ({1:1.1f})'.format( idx2word[inputs[w - Lmax]].encode('utf-8'), p) for w, p in zip(sample, ppp)] idz = sample.index(0) return ['{0} ({1:1.1f})'.format( idx2word[w].encode('utf-8'), p) if w < Lmax else '{0} ({1:1.1f})'.format( idx2word[inputs[w - Lmax]].encode('utf-8'), p) for w, p in zip(sample[:idz], ppp[:idz])] if inputs_unk is None: result, _, ppp = self.generate_(inputs[None, :], return_attend=return_attend) else: result, _, ppp = self.generate_(inputs_unk[None, :], return_attend=return_attend) source = '{}'.format(' '.join(cut_zero(inputs.tolist(), idx2word, Lmax=len(idx2word)))) target = '{}'.format(' '.join(cut_zero(outputs.tolist(), idx2word, Lmax=len(idx2word)))) decode = '{}'.format(' '.join(cut_zero(result, idx2word))) if display: print(source) print(target) print(decode) idz = result.index(0) p1, p2 = [np.asarray(p) for p in zip(*ppp)] print(p1.shape) import pylab as plt # plt.rc('text', usetex=True) # plt.rc('font', family='serif') visualize_(plt.subplots(), 1 - p1[:idz, :].T, grid=True, name=name) visualize_(plt.subplots(), 1 - p2[:idz, :].T, name=name) # visualize_(plt.subplots(), 1 - np.mean(p2[:idz, :], axis=1, keepdims=True).T) return target == decode
Example #5
Source File: analyser.py From spotpy with MIT License | 4 votes |
def plot_heatmap_griewank(results,algorithms, fig_name='heatmap_griewank.png'): """Example Plot as seen in the SPOTPY Documentation""" import matplotlib.pyplot as plt from matplotlib import ticker from matplotlib import cm font = {'family' : 'calibri', 'weight' : 'normal', 'size' : 20} plt.rc('font', **font) subplots=len(results) xticks=[-40,0,40] yticks=[-40,0,40] fig=plt.figure(figsize=(16,6)) N = 2000 x = np.linspace(-50.0, 50.0, N) y = np.linspace(-50.0, 50.0, N) x, y = np.meshgrid(x, y) z=1+ (x**2+y**2)/4000 - np.cos(x/np.sqrt(2))*np.cos(y/np.sqrt(3)) cmap = plt.get_cmap('autumn') rows=2.0 for i in range(subplots): amount_row = int(np.ceil(subplots/rows)) ax = plt.subplot(rows, amount_row, i+1) CS = ax.contourf(x, y, z,locator=ticker.LogLocator(),cmap=cm.rainbow) ax.plot(results[i]['par0'],results[i]['par1'],'ko',alpha=0.2,markersize=1.9) ax.xaxis.set_ticks([]) if i==0: ax.set_ylabel('y') if i==subplots/rows: ax.set_ylabel('y') if i>=subplots/rows: ax.set_xlabel('x') ax.xaxis.set_ticks(xticks) if i!=0 and i!=subplots/rows: ax.yaxis.set_ticks([]) ax.set_title(algorithms[i]) fig.savefig(fig_name, bbox_inches='tight')
Example #6
Source File: multiple_files.py From orbkit with GNU Lesser General Public License v3.0 | 4 votes |
def plot(self,mo_matrix,symmetry='1',title='All',x_label='index', y_label='MO coefficients',output_format='png', plt_dir='Plots',ylim=None,thresh=0.1,x0=0,grid=True,x_grid=None,**kwargs): '''Plots all molecular orbital coefficients of one self.symmetry.''' import pylab as plt from matplotlib.ticker import MultipleLocator import os display('Plotting data of self.symmetry %s to %s/' % (symmetry,plt_dir)) if not os.path.exists(plt_dir): os.makedirs(plt_dir) if numpy.ndim(mo_matrix) == 2: mo_matrix = mo_matrix[:,numpy.newaxis,:] shape = numpy.shape(mo_matrix) def plot_mo(i): fig=plt.figure() plt.rc('xtick', labelsize=16) plt.rc('ytick', labelsize=16) ax = plt.subplot(111) curves=[] for ij in range(shape[2]): Y = mo_matrix[:,i,ij] if x_grid is None: X = numpy.arange(len(Y))+x0 else: X = x_grid if max(numpy.abs(Y)) > thresh: curves.append(ax.plot(X,Y, '.-' ,linewidth=1.5)) plt.xlabel(x_label, fontsize=16); plt.ylabel(y_label, fontsize=16); plt.title('%s: %d.%s'% (title,i+1,symmetry)) plt.ylim(ylim) plt.tight_layout() return fig if output_format == 'pdf': from matplotlib.backends.backend_pdf import PdfPages output_fid = '%s.%s.pdf'% (title,symmetry.replace(' ','_')) display('\t%s' % output_fid) with PdfPages(os.path.join(plt_dir,output_fid)) as pdf: for i in range(shape[1]): fig = plot_mo(i) pdf.savefig(fig,**kwargs) plt.close() elif output_format == 'png': for i in range(shape[1]): fig = plot_mo(i) output_fid = '%d.%s.png' % (i+1,symmetry.replace(' ','_')) display('\t%s' % output_fid) fig.savefig(os.path.join(plt_dir, output_fid),format='png',**kwargs) plt.close() else: raise ValueError('output_format `%s` is not supported' % output_format)
Example #7
Source File: covc_encdec.py From CopyNet with MIT License | 4 votes |
def analyse_(self, inputs, outputs, idx2word, inputs_unk=None, return_attend=False, name=None, display=False): def cut_zero(sample, idx2word, ppp=None, Lmax=None): if Lmax is None: Lmax = self.config['dec_voc_size'] if ppp is None: if 0 not in sample: return ['{}'.format(idx2word[w].encode('utf-8')) if w < Lmax else '{}'.format(idx2word[inputs[w - Lmax]].encode('utf-8')) for w in sample] return ['{}'.format(idx2word[w].encode('utf-8')) if w < Lmax else '{}'.format(idx2word[inputs[w - Lmax]].encode('utf-8')) for w in sample[:sample.index(0)]] else: if 0 not in sample: return ['{0} ({1:1.1f})'.format( idx2word[w].encode('utf-8'), p) if w < Lmax else '{0} ({1:1.1f})'.format( idx2word[inputs[w - Lmax]].encode('utf-8'), p) for w, p in zip(sample, ppp)] idz = sample.index(0) return ['{0} ({1:1.1f})'.format( idx2word[w].encode('utf-8'), p) if w < Lmax else '{0} ({1:1.1f})'.format( idx2word[inputs[w - Lmax]].encode('utf-8'), p) for w, p in zip(sample[:idz], ppp[:idz])] if inputs_unk is None: result, _, ppp = self.generate_(inputs[None, :], return_attend=return_attend) else: result, _, ppp = self.generate_(inputs_unk[None, :], return_attend=return_attend) source = '{}'.format(' '.join(cut_zero(inputs.tolist(), idx2word, Lmax=len(idx2word)))) target = '{}'.format(' '.join(cut_zero(outputs.tolist(), idx2word, Lmax=len(idx2word)))) decode = '{}'.format(' '.join(cut_zero(result, idx2word))) if display: print source print target print decode idz = result.index(0) p1, p2 = [np.asarray(p) for p in zip(*ppp)] print p1.shape import pylab as plt # plt.rc('text', usetex=True) # plt.rc('font', family='serif') visualize_(plt.subplots(), 1 - p1[:idz, :].T, grid=True, name=name) visualize_(plt.subplots(), 1 - p2[:idz, :].T, name=name) # visualize_(plt.subplots(), 1 - np.mean(p2[:idz, :], axis=1, keepdims=True).T) return target == decode