我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用matplotlib.pylab.rcParams()。
def ConfigPylabDefaults(pylab, **kwargs): rcParams = pylab.rcParams rcParams['pdf.fonttype'] = 42 # Make fonts export as text (not bitmap) rcParams['ps.fonttype'] = 42 # Make fonts export as text (not bitmap) rcParams['text.usetex'] = False rcParams['legend.fontsize'] = 16 rcParams['axes.titlesize'] = 18 rcParams['axes.labelsize'] = 18 rcParams['xtick.labelsize'] = 16 rcParams['ytick.labelsize'] = 16 rcParams['figure.figsize'] = ExportInfo['W_in'], ExportInfo['H_in'] rcParams['figure.dpi'] = ExportInfo['dpi'] rcParams['figure.subplot.left'] = 0.15 rcParams['figure.subplot.right'] = 0.95 rcParams['figure.subplot.bottom'] = 0.15 rcParams['figure.subplot.top'] = 0.95 rcParams['savefig.dpi'] = ExportInfo['dpi'] rcParams.update(kwargs)
def onehist(x,xlabel='',fontsize=12): """ Script that plots the histogram of x with the corresponding xlabel. """ pylab.clf() pylab.rcParams.update({'font.size': fontsize}) pylab.hist(x,histtype='stepfilled') pylab.legend() #### Change the X-axis appropriately #### pylab.xlabel(xlabel) pylab.ylabel('Number') pylab.draw() pylab.show()
def threehistsx(x1,x2,x3,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',fig=1,fontsize=12,bins1=10,bins2=10,bins3=10): """ Script that pretty-plots three histograms of quantities x1, x2 and x3. Arguments: :param x1,x2,x3: arrays with data to be plotted :param x1leg, x2leg, x3leg: legends for each histogram :param fig: which plot window should I use? Example: x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10) >>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)') Inspired by http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label. """ pylab.rcParams.update({'font.size': fontsize}) pylab.figure(fig) pylab.clf() pylab.subplot(3,1,1) pylab.hist(x1,label=x1leg,color='b',bins=bins1) pylab.legend(loc='best',frameon=False) pylab.subplot(3,1,2) pylab.hist(x2,label=x2leg,color='r',bins=bins2) pylab.legend(loc='best',frameon=False) pylab.subplot(3,1,3) pylab.hist(x3,label=x3leg,color='y',bins=bins3) pylab.legend(loc='best',frameon=False) pylab.minorticks_on() pylab.subplots_adjust(hspace=0.15) pylab.draw() pylab.show()
def plot_single_scale(scale_lst, size): pylab.rcParams['figure.figsize'] = size, size/2 plt.figure() for i in range(0, len(scale_lst)): s=plt.subplot(1,5,i+1) plt.imshow(1-scale_lst[i], cmap = cm.Greys_r) #plt.imshow(1-scale_lst[i]) s.set_xticklabels([]) s.set_yticklabels([]) s.yaxis.set_ticks_position('none') s.xaxis.set_ticks_position('none') plt.tight_layout()
def twohists(x1,x2,xmin,xmax,range=None,x1leg='$x_1$',x2leg='$x_2$',xlabel='',fig=1,sharey=False,fontsize=12,bins1=10,bins2=10): """ Script that plots two histograms of quantities x1 and x2 sharing the same X-axis. :param x1,x2: arrays with data to be plotted :param xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range for both histograms. :param x1leg, x2leg: legends for each histogram :param xlabel: self-explanatory. :param bins1,bins2: number of bins in each histogram :param fig: which plot window should I use? :param range: in the form (xmin,xmax), same as range argument for hist and applied to both histograms. Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_. """ pylab.rcParams.update({'font.size': fontsize}) fig=pylab.figure(fig) pylab.clf() a=fig.add_subplot(2,1,1) if sharey==True: b=fig.add_subplot(2,1,2, sharex=a, sharey=a) else: b=fig.add_subplot(2,1,2, sharex=a) a.hist(x1,bins1,label=x1leg,color='b',histtype='stepfilled',range=range) a.legend(loc='best',frameon=False) a.set_xlim(xmin,xmax) b.hist(x2,bins2,label=x2leg,color='r',histtype='stepfilled',range=range) b.legend(loc='best',frameon=False) pylab.setp(a.get_xticklabels(), visible=False) b.set_xlabel(xlabel) b.set_ylabel('Number',verticalalignment='bottom') pylab.minorticks_on() pylab.subplots_adjust(hspace=0.15) pylab.draw() pylab.show()
def threehists(x1,x2,x3,xmin,xmax,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',xlabel='',fig=1,sharey=False,fontsize=12): """ Script that plots three histograms of quantities x1, x2 and x3 sharing the same X-axis. Arguments: - x1,x2,x3: arrays with data to be plotted - xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range for both histograms. - x1leg, x2leg, x3leg: legends for each histogram - xlabel: self-explanatory. - sharey: sharing the Y-axis among the histograms? - fig: which plot window should I use? Example: x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10) >>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)',sharey=True) Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_. """ pylab.rcParams.update({'font.size': fontsize}) fig=pylab.figure(fig) pylab.clf() a=fig.add_subplot(3,1,1) if sharey==True: b=fig.add_subplot(3,1,2, sharex=a, sharey=a) c=fig.add_subplot(3,1,3, sharex=a, sharey=a) else: b=fig.add_subplot(3,1,2, sharex=a) c=fig.add_subplot(3,1,3, sharex=a) a.hist(x1,label=x1leg,color='b',histtype='stepfilled') a.legend(loc='best',frameon=False) a.set_xlim(xmin,xmax) b.hist(x2,label=x2leg,color='r',histtype='stepfilled') b.legend(loc='best',frameon=False) c.hist(x3,label=x3leg,color='y',histtype='stepfilled') c.legend(loc='best',frameon=False) pylab.setp(a.get_xticklabels(), visible=False) pylab.setp(b.get_xticklabels(), visible=False) c.set_xlabel(xlabel) b.set_ylabel('Number') pylab.minorticks_on() pylab.subplots_adjust(hspace=0.15) pylab.draw() pylab.show()
def fourcumplot(x1,x2,x3,x4,xmin,xmax,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',x4leg='$x_3$',xlabel='',ylabel='$N(x>x\')$',fig=1,sharey=False,fontsize=12,bins1=50,bins2=50,bins3=50,bins4=50): """ Script that plots the cumulative histograms of four variables x1, x2, x3 and x4 sharing the same X-axis. For each bin, Y is the fraction of the sample with values above X. Arguments: - x1,x2,x3,x4: arrays with data to be plotted - xmin,xmax: lower and upper range of plotted values, will be used to set a consistent x-range for both histograms. - x1leg, x2leg, x3leg, x4leg: legends for each histogram - xlabel: self-explanatory. - sharey: sharing the Y-axis among the histograms? - bins1,bins2,...: number of bins in each histogram - fig: which plot window should I use? Inspired by `Scipy <http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label>`_. v1 Jun. 2012: inherited from fourhists. """ pylab.rcParams.update({'font.size': fontsize}) fig=pylab.figure(fig) pylab.clf() a=fig.add_subplot(4,1,1) if sharey==True: b=fig.add_subplot(4,1,2, sharex=a, sharey=a) c=fig.add_subplot(4,1,3, sharex=a, sharey=a) d=fig.add_subplot(4,1,4, sharex=a, sharey=a) else: b=fig.add_subplot(4,1,2, sharex=a) c=fig.add_subplot(4,1,3, sharex=a) d=fig.add_subplot(4,1,4, sharex=a) a.hist(x1,bins1,label=x1leg,color='b',cumulative=-True,normed=True,histtype='stepfilled') a.legend(loc='best',frameon=False) a.set_xlim(xmin,xmax) b.hist(x2,bins2,label=x2leg,color='r',cumulative=-True,normed=True,histtype='stepfilled') b.legend(loc='best',frameon=False) c.hist(x3,bins3,label=x3leg,color='y',cumulative=-True,normed=True,histtype='stepfilled') c.legend(loc='best',frameon=False) d.hist(x4,bins4,label=x4leg,color='g',cumulative=-True,normed=True,histtype='stepfilled') d.legend(loc='best',frameon=False) pylab.setp(a.get_xticklabels(), visible=False) pylab.setp(b.get_xticklabels(), visible=False) pylab.setp(c.get_xticklabels(), visible=False) d.set_xlabel(xlabel) c.set_ylabel(ylabel) pylab.minorticks_on() pylab.subplots_adjust(hspace=0.15) pylab.draw() pylab.show()
def illustrate(Colors=Colors): if hasattr(Colors, 'colors'): Colors = Colors.colors from matplotlib import pylab rcParams = pylab.rcParams rcParams['pdf.fonttype'] = 42 rcParams['ps.fonttype'] = 42 rcParams['text.usetex'] = False rcParams['xtick.labelsize'] = 20 rcParams['ytick.labelsize'] = 20 rcParams['legend.fontsize'] = 25 import bnpy Data = get_data(T=1000, nDocTotal=8) for k in xrange(K): zmask = Data.TrueParams['Z'] == k pylab.plot(Data.X[zmask, 0], Data.X[zmask, 1], '.', color=Colors[k], markeredgecolor=Colors[k], alpha=0.4) sigEdges = np.flatnonzero(transPi[k] > 0.0001) for j in sigEdges: if j == k: continue dx = mus[j, 0] - mus[k, 0] dy = mus[j, 1] - mus[k, 1] pylab.arrow(mus[k, 0], mus[k, 1], 0.8 * dx, 0.8 * dy, head_width=2, head_length=4, facecolor=Colors[k], edgecolor=Colors[k]) tx = 0 - mus[k, 0] ty = 0 - mus[k, 1] xy = (mus[k, 0] - 0.2 * tx, mus[k, 1] - 0.2 * ty) ''' pylab.annotate( u'\u27F2', xy=(mus[k,0], mus[k,1]), color=Colors[k], fontsize=35, ) ''' pylab.gca().yaxis.set_ticks_position('left') pylab.gca().xaxis.set_ticks_position('bottom') pylab.axis('image') pylab.ylim([-38, 38]) pylab.xlim([-38, 38])