pylab.savefig() and pylab.show() image difference
- by Jack1990
I'm making an script to automatically create plots from .xvg files,
but there's a problem when I'm trying to use pylab's savefig() method.
Using pylab.show() and saving from there, everything's fine.
Using pylab.show()
Using pylab.savefig()
def producePlot(timestep, energy_values,type_line = 'r', jump = 1,finish = 100):
    fc = sp.interp1d(timestep[::jump], energy_values[::jump],kind='cubic')
    xnew = numpy.linspace(0, finish, finish*2)
    pylab.plot(xnew, fc(xnew),type_line)
    pylab.xlabel('Time in ps ')
    pylab.ylabel('kJ/mol')
    pylab.xlim(xmin=0, xmax=finish)
def produceSimplePlot(timestep, energy_values,type_line = 'r', jump = 1,finish = 100):
    pylab.plot(timestep, energy_values,type_line)
    pylab.xlabel('Time in ps ')
    pylab.ylabel('kJ/mol')
    pylab.xlim(xmin=0, xmax=finish)
def linearRegression(timestep, energy_values, type_line = 'g'): #, jump = 1,finish = 100):
    from scipy import stats
    import numpy
    #print 'fuck'
    timestep = numpy.asarray(timestep)
    slope, intercept, r_value, p_value, std_err = stats.linregress(timestep,energy_values)
    line = slope*timestep+intercept
    pylab.plot(timestep, line, type_line)
def plottingTime(Title,file_name, timestep, energy_values ,loc, jump , finish):
    pylab.title(Title)
    producePlot(timestep,energy_values, 'b',jump, finish)
    linearRegression(timestep,energy_values)
    import numpy
    Average = numpy.average(energy_values)
    #print Average
    pylab.legend(("Average = %.2f" %(Average),'Linear Reg'),loc)
    #pylab.show()
    pylab.savefig('%s.jpg' %file_name[:-4], bbox_inches= None, pad_inches=0)
#if __name__ == '__main__':
    #plottingTime(Title,timestep1, energy_values, jump  =10, finish = 4800)
def specialCase(Title,file_name, timestep, energy_values,loc, jump, finish):
    #print 'Working here ...?'
    pylab.title(Title)
    producePlot(timestep,energy_values, 'b',jump, finish)
    import numpy
    from pylab import *
    Average = numpy.average(energy_values)
    #print Average
    pylab.legend(("Average = %.2g" %(Average), Title),loc)
    locs,labels = yticks()
    yticks(locs, map(lambda x: "%.3g" % x, locs))
    #pylab.show()
    pylab.savefig('%s.jpg' %file_name[:-4] , bbox_inches= None, pad_inches=0)
Thanks in advance,
John