python - Matplotlib - Can't see specific plots in the graph -
in following script, don't know why plots corresponding line1 , line2 (when n <=12) not generated in a.png file. see line3 being generated. have used similar codes worked earlier doesn't show line1 , line2 in plots. thoughts?
sorry posting such long script. wanted make sure don't miss anything.
import matplotlib.pyplot plt import matplotlib; import matplotlib.gridspec gridspec matplotlib.ticker import autominorlocator import pylab pl import numpy np #changing default fonts throughout matplotlib.rc('font',**{'family':'sans-serif','sans-serif':['helvetica'], 'weight':'bold'}) matplotlib.font_manager import fontmanager, fontproperties matplotlib.rcparams['mathtext.fontset'] = 'custom' matplotlib.rcparams['mathtext.rm'] = 'helvetica' matplotlib.rcparams['mathtext.it'] = 'helvetica:italic' matplotlib.rcparams['mathtext.bf'] = 'helvetica:bold' font= fontproperties(weight='bold',size=20) #load text , columns different variables #-----------functions----------- def ax_lw(): axis in ['top','bottom','left','right']: ax.spines[axis].set_linewidth(3) def tlabels(): tick in ax.xaxis.get_ticklabels(): tick.set_fontsize(28) tick.set_weight('bold') tick in ax.yaxis.get_ticklabels(): tick.set_fontsize(28) tick.set_weight('bold') def format(): ax.set_ylabel(r'$\mathrm{ \bf{\delta{}e}}$',fontsize=30,fontweight='bold') ax.tick_params(axis='x', which='both', direction='in', length=10, width=3, pad=8, labelbottom='on', bottom='on', top='off') # labelsize='small' ax.tick_params(axis='y', which='major', direction='in', length=10, width=3, pad=8, right='off') # labelsize='small' ax.tick_params(axis='y', which='minor', direction='in', length=6, width=2, right='off') # labelsize='small' ax.set_xticks(r); ax.set_xticklabels(data[list[3]],rotation=0) minorlocator = autominorlocator(2); ax.yaxis.set_minor_locator(minorlocator) #ax.text(5.0,-0.25, r'$\mathrm{ \bf{\delta{}e_{ads}^{vac}}=-0.39{ }ev}$', fontsize=20) #-------------------------------pbe---------------- list=[]; count = 0 num,i in enumerate(open("pbe")): if i.strip(): count += 1 if num == 0: cols = i.strip().split() num,i in enumerate(cols): list.append(cols[num]) data = np.genfromtxt('pbe', names=true, dtype=none, usecols=list) r = np.arange(0,(count-1)*1.5,1.5) #-1 excluding first line #plot fig = plt.figure(figsize=(28.8,12), dpi=300) n=4; m=count=0 axis = [(-0.5,8, -1.0,0.2)] * 5 abcde = ['a)', 'b)', 'c)', 'd)', 'e)'] #gs = gridspec.gridspec(4, 6) j in range(2): k in range(3): #for j in range(0,4,2): # k in range(0,6,2): if (n <=12 , count <=4): # ax = plt.subplot(gs[j:j+2,k:k+2]) ax = plt.subplot2grid((2,3), (j,k)) line1, = ax.plot(r,data[list[n]], marker='v', markeredgecolor='black', color='black', linestyle='-', markersize=18, linewidth=3) line2, = ax.plot(r,data[list[n+1]], marker='^', markeredgecolor='black', color='red', linestyle='-', markersize=18, linewidth=3) ax_lw(); tlabels(); format(); plt.axis(axis[m]) plt.axhline(data[list[2]][m],linestyle='--', linewidth=2,color='black') ax.text(-0.16, 0.95, abcde[count], transform=ax.transaxes, fontsize=28, fontweight='bold') n += 2; m+=1; count+=1 n=14; m = 0 in range(2): j in range(3): if m < 5: ax = plt.subplot2grid((2,3), (i,j)) line3, = ax.plot(r,data[list[n]], marker='v', markeredgecolor='black', color='red', linestyle='-', markersize=18, linewidth=3) ax_lw(); tlabels(); format(); plt.axis(axis[m]) n +=1; m+= 1 fig.set_tight_layout(true) plt.savefig('a.png',dpi=300,format='png',orientation='landscape')
the data looks 1 in below figure , can found in link below:
i don't have data cannot run this. however, suspect overwriting ax
redefining second time before line3. example:
for j in range(2): k in range(3): if (n <=12 , count <=4): # ax = plt.subplot(gs[j:j+2,k:k+2]) ax = plt.subplot2grid((2,3), (j,k)) line1, = ax.plot(r,data[list[n]], marker='v', markeredgecolor='black', color='black', linestyle='-', markersize=18, linewidth=3) line2, = ax.plot(r,data[list[n+1]], marker='^', markeredgecolor='black', color='red', linestyle='-', markersize=18, linewidth=3)
which follow with:
n=14; m = 0 in range(2): j in range(3): if m < 5: ax = plt.subplot2grid((2,3), (i,j)) line3, = ax.plot(r,data[list[n]], marker='v', markeredgecolor='black', color='red', linestyle='-', markersize=18, linewidth=3)
before finally:
plt.savefig('a.png',dpi=300,format='png',orientation='landscape')
Comments
Post a Comment