我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用matplotlib.pyplot.minorticks_on()。
def save_image(real_data, fake_data, filename): assert real_data.shape == fake_data.shape import warnings warnings.filterwarnings("ignore", category=FutureWarning) import numpy as np import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt fig, ax = plt.subplots() plt.scatter(fake_data[:,0], fake_data[:,1], color='red', label='noise (fake, sampled)') plt.scatter(real_data[:,0], real_data[:,1], color='blue', label='hidden (real, inferred)') #plt.axis('equal') plt.legend(loc='upper right', fancybox=True, shadow=True, fontsize=11) plt.grid(True) plt.xlim(-5, 5) plt.ylim(-5, 5) plt.minorticks_on() plt.xlabel('x', fontsize=14, color='black') plt.ylabel('y', fontsize=14, color='black') plt.title('z samples (of first two dimensions)') plt.savefig(filename) plt.close()
def save_image_fake(fake_data, filename): #import warnings #warnings.filterwarnings("ignore", category=FutureWarning) #import numpy as np #import matplotlib #matplotlib.use('Agg') #import matplotlib.pyplot as plt fig, ax = plt.subplots() #plt.scatter(real_data[:,0], real_data[:,1], color='blue', label='real') plt.scatter(fake_data[:,0], fake_data[:,1], color='red', label='fake') plt.axis('equal') #plt.legend(loc='upper right', fancybox=True, shadow=True, fontsize=11) plt.grid(True) plt.xlim(-25, 25) plt.ylim(-25, 25) plt.minorticks_on() plt.xlabel('x', fontsize=14, color='black') plt.ylabel('y', fontsize=14, color='black') #plt.title('Toy dataset') plt.savefig(filename) plt.close()
def save_image_real(real_data, filename): #import warnings #warnings.filterwarnings("ignore", category=FutureWarning) #import numpy as np #import matplotlib #matplotlib.use('Agg') #import matplotlib.pyplot as plt fig, ax = plt.subplots() plt.scatter(real_data[:,0], real_data[:,1], color='blue', label='real') #plt.scatter(fake_data[:,0], fake_data[:,1], color='red', label='fake') plt.axis('equal') #plt.legend(loc='upper right', fancybox=True, shadow=True, fontsize=11) plt.grid(True) plt.xlim(-25, 25) plt.ylim(-25, 25) plt.minorticks_on() plt.xlabel('x', fontsize=14, color='black') plt.ylabel('y', fontsize=14, color='black') #plt.title('Toy dataset') plt.savefig(filename) plt.close()
def save_image(real_data, fake_data, filename): #import warnings #warnings.filterwarnings("ignore", category=FutureWarning) #import numpy as np #import matplotlib #matplotlib.use('Agg') #import matplotlib.pyplot as plt fig, ax = plt.subplots() plt.scatter(real_data[:,0], real_data[:,1], color='blue', label='real') plt.scatter(fake_data[:,0], fake_data[:,1], color='red', label='fake') #plt.axis('equal') plt.legend(loc='upper right', fancybox=True, shadow=True, fontsize=11) plt.grid(True) plt.xlim(-25, 25) plt.ylim(-25, 25) plt.minorticks_on() plt.xlabel('x', fontsize=14, color='black') plt.ylabel('y', fontsize=14, color='black') plt.title('Toy dataset') plt.savefig(filename) plt.close()
def paper_single_mult_ax(nrows=1, ncols=1, **kwargs): #import matplotlib as mpl paper_single(FF=max(nrows,ncols)) f, ax = plt.subplots(nrows=nrows, ncols=ncols, **kwargs) plt.minorticks_on() ylocator6 = plt.MaxNLocator(5) xlocator6 = plt.MaxNLocator(6) if len(ax.shape) > 1: for axrow in ax: for axcol in axrow: axcol.xaxis.set_major_locator(xlocator6) axcol.yaxis.set_major_locator(ylocator6) else: for axcol in ax: axcol.xaxis.set_major_locator(xlocator6) axcol.yaxis.set_major_locator(ylocator6) return f, ax
def show_figure(self): self.maxx *= 1.2 self.maxy *= 1.2 plt.xlim(0,self.maxx) plt.ylim(0,self.maxy) plt.xticks(np.linspace(0,self.maxx,8)) plt.yticks(np.linspace(0,self.maxy,10)) plt.title(r"Trajectory of a cannon shell,T = %sK" %self.t) plt.xlabel('x(km)') plt.ylabel('y(km)') plt.legend(loc = 'upper right',fontsize = 'x-small') plt.minorticks_on() plt.grid() plt.show()
def paper_single_ax(TW = 6.64, AR = 0.74, FF = 1.): #import matplotlib as mpl paper_single(TW=TW, AR=AR, FF=FF) f = plt.figure() ax = plt.subplot(111) plt.minorticks_on() ylocator6 = plt.MaxNLocator(5) xlocator6 = plt.MaxNLocator(6) ax.xaxis.set_major_locator(xlocator6) ax.yaxis.set_major_locator(ylocator6) return f, ax
def paper_double_ax(): #import matplotlib as mpl paper_single(TW = 12) f = plt.figure() ax = plt.subplot(111) plt.minorticks_on() ylocator6 = plt.MaxNLocator(5) xlocator6 = plt.MaxNLocator(6) ax.xaxis.set_major_locator(xlocator6) ax.yaxis.set_major_locator(ylocator6) return f, ax
def paper_double_mult_ax(nrows=1, ncols=1, setticks=True, **kwargs): #import matplotlib as mpl paper_single() TW = 6.97*2 AR = 0.74 FF = 1. mpl.rc('figure', figsize=(FF*TW, FF*TW*AR), dpi=200) mpl.rc('figure.subplot', left=0.1, right=0.97, bottom=0.1, top=0.97) mpl.rc('font', size=24.0, family="serif", serif="CM") f, ax = plt.subplots(nrows=nrows, ncols=ncols, **kwargs) plt.minorticks_on() if setticks: ylocator6 = plt.MaxNLocator(5) xlocator6 = plt.MaxNLocator(6) if len(ax.shape) > 1: for axrow in ax: for axcol in axrow: axcol.xaxis.set_major_locator(xlocator6) axcol.yaxis.set_major_locator(ylocator6) else: for axcol in ax: axcol.xaxis.set_major_locator(xlocator6) axcol.yaxis.set_major_locator(ylocator6) return f, ax
def make_ax3(): paper_single(TW=8, AR=0.9) f = plt.figure() from matplotlib.ticker import NullFormatter, MaxNLocator nullfmt = NullFormatter() # no labels # definitions for the axes left, width = 0.1, 0.65 bottom, height = 0.1, 0.6 bottom_h = bottom+height+0.02 left_h = left+width+0.02 rect_scatter = [left, bottom, width, height] rect_histx = [left, bottom_h, width, 0.2] rect_histy = [left_h, bottom, 0.2, height] ax = plt.axes(rect_scatter) plt.minorticks_on() axx = plt.axes(rect_histx) plt.minorticks_on() axy = plt.axes(rect_histy) plt.minorticks_on() # no labels axx.xaxis.set_major_formatter(nullfmt) axy.yaxis.set_major_formatter(nullfmt) axy.xaxis.set_major_locator(MaxNLocator(3)) axx.yaxis.set_major_locator(MaxNLocator(3)) return f,ax,axx,axy
def iplt(fdic, key, cut=None, ax=None, cbar=None, smth=None, nolabels=None, lblsz='small', **kwargs): """ A wrapper function for imshow to do most tedious stuff for my simulations """ old_ax = plt.gca() # Get Current Axis if ax is None: ax = old_ax else: plt.sca(ax) # Set Current Axis if type(key) is str: plt_val = fdic[key] else : plt_val = key if cut is None: if len(plt_val.shape) == 1: IDX=np.s_[:] elif len(plt_val.shape) == 2: IDX=np.s_[:,0] else: IDX=np.s_[:,0,0] else: if len(plt_val.shape) == 1: IDX=compute1didx([fdic['xx']],cut) elif len(plt_val.shape) == 2: IDX=compute1didx([fdic['xx'],fdic['yy']],cut) else: IDX=compute1didx([fdic['xx'],fdic['yy'],fdic['zz']],cut) im = ax.plot(fdic['xx'],plt_val[IDX], **kwargs) ax.autoscale(False) if nolabels is None: ax.set_xlabel(r'$X (d_i)$',size=lblsz) ax.set_ylabel(key,size=lblsz) ax.xaxis.set_tick_params(which='both',labelsize=lblsz) ax.yaxis.set_tick_params(which='both',labelsize=lblsz) plt.minorticks_on() plt.sca(old_ax) return im