Here is what I am trying to do. I have the following code:
# -*- coding: utf-8 -*- from pylab import * import matplotlib.pyplot as plt import numpy as np ### processing function def store(var,textFile): data=loadtxt(textFile,skiprows=1) it=[] eps=[] sig=[] tc=[] sc=[] te=[] se=[] ubf=[] for i in range(0,len(data)): it.append(float(data[i,1])) eps.append(float(data[i,0])) sig.append(float(data[i,4])) tc.append(float(data[i,6])) sc.append(float(data[i,2])) te.append(float(data[i,7])) se.append(float(data[i,3])) ubf.append(float(data[i,8])) var.append(it) var.append(eps) var.append(sig) var.append(tc) var.append(sc) var.append(te) var.append(se) var.append(ubf) ### data input dataFile1='0101005_5k_tensionTestCentreCrack_l0.001a0_r0.02' a1=[] store(a1,dataFile1) dataFile2='0101005_10k_tensionTestCentreCrack_l0.001a0_r0.02' a2=[] store(a2,dataFile2) dataFile3='0101005_20k_tensionTestCentreCrack_l0.001a0_r0.01' a3=[] store(a3,dataFile3) dataFile4='0101005_40k_tensionTestCentreCrack_l0.001a0_r0.02' a4=[] store(a4,dataFile4) dataFile5='0101005_80k_tensionTestCentreCrack_l0.001a0_r0.02' a5=[] store(a5,dataFile5) dataFile6='0101005_120k_tensionTestCentreCrack_l0.001a0_r0.02' a6=[] store(a6,dataFile6) dataFile7='0101005_200k_tensionTestCentreCrack_l0.001a0_r0.02' a7=[] store(a7,dataFile7) ### plot control rcParams.update({'legend.numpoints':1,'font.size': 20,'axes.labelsize':25,'xtick.major.pad':10,'ytick.major.pad':10,'legend.fontsize':20}) lw=2 ms=10 ### plots #savefig(dataFile1+'_sigVSeps.eps',dpi=1000,format='eps',transparent=False) hcl=0.005 ###plot of fracture toughness vs. square root of mean radius A=[0.0023**0.5, 0.0019**0.5, 0.0015**0.5, 0.0012**0.5, 0.0009**0.5, 0.0008**0.5, 0.0007**0.5] B=[max(a1[2])*((pi*hcl)**0.5) ,max(a2[2])*((pi*hcl)**0.5) ,max(a3[2])*((pi*hcl)**0.5), max(a4[2])*((pi*hcl)**0.5), max(a5[2])*((pi*hcl)**0.5), max(a6[2])*((pi*hcl)**0.5), max(a7[2])*((pi*hcl)**0.5)] #B=[max(a1[2]),max(a2[2]),max(a3[2]),max(a4[2])] figure(4,figsize=(12,10)) grid() xlabel('$\sqrt{R} [m]$') ##axis(xmin=0,xmax=0.1) plot(A,[x/1e6 for x in B],'-ko',linewidth=lw) for xy in zip(A,[x/1e6 for x in B]): annotate('(%s, %s)' % xy, xy=xy, textcoords='data') ylabel(r'$K_{Ic} [MPa.\sqrt{m}]$') title(r'Fracture toughness $(K_{Ic})$ as a function of square root of mean particle radius $\sqrt{R}$', fontsize=14, color='blue') G=[(1.42*1e-5, 8.5*1e-2), (1.19*1e-5, 7.8*1e-2), (1.03*1e-5, 6*1e-2), (8.95*1e-6, 4.7*1e-2), (7.63*1e-6, 3.8*1e-2), (7.12*1e-6, 3.2*1e-2), (5.72*1e-6, 2.6*1e-2)] PN=[5*1e3, 10*1e3, 20*1e3, 40*1e3, 80*1e3, 120*1e3, 200*1e3] figure(5,figsize=(12,10)) for PNe, Ge, in zip(PN, G): scatter([PNe]*len(Ge), Ge, color=['blue', 'green']) grid() xlim(xmin=0, xmax=200000) #ylim(ymin=0, ymax=1) xlabel('Number of particles') ylabel(r'Energy release rate') figure(6,figsize=(12,10)) ax1=subplot(1,1,1) grid() xlabel(r'$\varepsilon_1$ [millistrain]') #axis(xmin=0,xmax=0.12) ax1.plot([x*1e3 for x in a1[1]],[x/1e6 for x in a1[2]],'-b',linewidth=lw) ax1.plot([x*1e3 for x in a2[1]],[x/1e6 for x in a2[2]],'-g',linewidth=lw) ax1.plot([x*1e3 for x in a3[1]],[x/1e6 for x in a3[2]],'-r',linewidth=lw) ax1.plot([x*1e3 for x in a4[1]],[x/1e6 for x in a4[2]],'-y',linewidth=lw) ax1.plot([x*1e3 for x in a5[1]],[x/1e6 for x in a5[2]],'-m',linewidth=lw) ax1.plot([x*1e3 for x in a6[1]],[x/1e6 for x in a6[2]],'-c',linewidth=lw) ax1.plot([x*1e3 for x in a7[1]],[x/1e6 for x in a7[2]],'-k',linewidth=lw) ylabel(r'$\sigma_1$ [MPa]') #legend(('5k','10k','20k','40k'),2) #axis(ymin=0,ymax=10) ax2 = ax1.twinx() ax2.plot([x*1e3 for x in a1[1]],[x+y for x,y in zip(a1[5],a1[6])],'--b',linewidth=lw) ax2.plot([x*1e3 for x in a2[1]],[x+y for x,y in zip(a2[5],a2[6])],'--g',linewidth=lw) ax2.plot([x*1e3 for x in a3[1]],[x+y for x,y in zip(a3[5],a3[6])],'--r',linewidth=lw) ax2.plot([x*1e3 for x in a4[1]],[x+y for x,y in zip(a4[5],a4[6])],'--y',linewidth=lw) ax2.plot([x*1e3 for x in a5[1]],[x+y for x,y in zip(a5[5],a5[6])],'--m',linewidth=lw) ax2.plot([x*1e3 for x in a6[1]],[x+y for x,y in zip(a6[5],a6[6])],'--c',linewidth=lw) ax2.plot([x*1e3 for x in a7[1]],[x+y for x,y in zip(a7[5],a7[6])],'--k',linewidth=lw) ylabel('energy released by microcracking [J]') #axis(ymin=0,ymax=200) ### show or save show() As you see in my code figure 4 appears as this: Floating numbers on the plot are too long
1.How can I change the precision of floating numbers on the plot? I would like to have only 3 decimal. Here is what I did:
A=[float("{0:.2e}".format(0.0023**0.5)), float("{0:.2e}".format(0.0019**0.5)), float("{0:.2e}".format(0.0015**0.5)), float("{0:.2e}".format(0.0012**0.5)), float("{0:.2e}".format(0.0009**0.5)), float("{0:.2e}".format(0.0008**0.5)), float("{0:.2e}".format(0.0007**0.5))] B=[float("{0:.2e}".format(max(a1[2])*((pi*hcl)**0.5))) ,float("{0:.2e}".format(max(a2[2])*((pi*hcl)**0.5))) ,float("{0:.2e}".format(max(a3[2])*((pi*hcl)**0.5))), float("{0:.2e}".format(max(a4[2])*((pi*hcl)**0.5))), float("{0:.2e}".format(max(a5[2])*((pi*hcl)**0.5))), float("{0:.2e}".format(max(a6[2])*((pi*hcl)**0.5))), float("{0:.2e}".format(max(a7[2])*((pi*hcl)**0.5)))] It actually does the job but doesn't seem very intuitive to me. So the question is : Is there any other way to do the same thing? For instance how can I define the floating precision for my whole script?
Thanks
