Sorry it took me a while to get back to you. I have finally written some
code to replicate the problem. I have attached a file with it.
Thank you very much in advance,
Bruno Santos
2012/1/19 Tony Yu <tsy...@gmail.com>
>
>
> On Thu, Jan 19, 2012 at 12:07 PM, Bruno Santos <bacmsan...@gmail.com>wrote:
>
>> Hello everyone,
>>
>> I have been using matplotlib 0.99.3 to write some down. But I had to
>> upgrade my OS and so installed the last version of the library 1.1.0. But
>> unfortunately when I try to run my code I get the following error:
>> raise ValueError, 'Path lacks initial MOVETO'
>> ValueError: Path lacks initial MOVETO
>>
>> I have been goggling it and saw some reports about it when using a vector
>> containing zeros for which I apply a log and then trying to plot this. But
>> the reports seem to indicate this was fixed in a svn version I can't access
>> anymore.
>> Can anyone point me on the correct direction to solve this problem?
>>
>> Thank you very much in advance,
>> Bruno Santos
>>
>> Could you provide a bit more information: Are you calling `Path`
> directly? If not, do you know what in your code is calling it? A minimal,
> runnable example would be very helpful.
>
> Cheers,
> -Tony
>
>
import numpy
from matplotlib.backends.backend_pdf import PdfPages
import pylab
class locus:
def __init__(self,nStartCoord,nEndCoord,nLength,nSize,zChr = 'None'):
"""
"""
self.nStartCoord = nStartCoord
self.nEndCoord = nEndCoord
self.zChr = zChr
self.aSCounts = numpy.zeros(nLength,dtype='Float64')
self.aASCounts = numpy.zeros(nLength,dtype='Float64')
self.nLength = nLength
self.nSize = nSize
self.pValue = 0.0
self.tMinIndex = (0,0)
def plot(self,display=False,all=True):
"""
self.plot(self,display=False,all=True)
all <- Flag can be used to plot the all locus or just the most significant part
Plot the number of signatures in the sense and anti sense
strand for the current locus.
"""
#Plot sense strand
#Create a figure object
fig = pylab.figure(figsize=(16,9),dpi=160)
print 'ok1'
#Define Patch objects for the legend
#non_phase_pos = Patch(edgecolor='b', facecolor='b')
#phase_pos = Patch(edgecolor='r', facecolor='r')
#Plot title and legend for the figure
if all:
pylab.suptitle('%s:%d..%d with log p-value = %.2f' % (self.zChr,self.nStartCoord,self.nEndCoord,self.pValue),fontsize=24,x=0.39)
aSCounts = numpy.log(self.aSCounts[self.nSize:-self.nSize])
aASCounts = numpy.log(self.aASCounts[self.nSize:-self.nSize])
#get the first position in phase
nFirstPos = self.tMinIndex[0]-self.tMinIndex[0]/self.nSize*self.nSize
phasedIndex = numpy.arange(nFirstPos,len(aSCounts),self.nSize)
else:
pylab.suptitle('Most significant region on phased sRNA loci in %s:%d..%d with log p-value = %.2f' % (self.zChr,self.nStartCoord+self.tMinIndex[0],self.nStartCoord+self.tMinIndex[1],self.pValue),fontsize=18,x=0.45)
aSCounts = numpy.log(self.aSCounts[self.tMinIndex[0]:self.tMinIndex[1]])
aASCounts = numpy.log(self.aASCounts[self.tMinIndex[0]:self.tMinIndex[1]])
phasedIndex = numpy.arange(0,len(aSCounts),self.nSize)
print 'ok3'
#pylab.figlegend([phase_pos,non_phase_pos],['Phased positions','Out of Phase positions'],'upper right',prop={'size':8})
#Produce the plot
pylab.subplot(211)
pylab.subplots_adjust(left=0.05, bottom=0.06, right=0.99, top=0.92, hspace=0.16)
pylab.xlabel('Relative position',fontsize= 14)
pylab.ylabel('Number of small RNAs',fontsize= 14)
pylab.bar(range(len(aSCounts)),aSCounts,color='b',width=1.0,edgecolor='b')
pylab.bar(phasedIndex,aSCounts[phasedIndex],color='r',width=2,edgecolor='r',alpha=1,align='center')
yaxis_pos = max(aSCounts)/3.0*2 #Compute the position where to place the markers of phased positions
try:#The sense strand may not contain any sRNA matching to it
pylab.scatter(phasedIndex, [yaxis_pos]*len(phasedIndex), marker='d', color='white',edgecolor='black')
except:pass
try:#The sense strand may not have any sRNA in phase
phasedIndexOccupied = phasedIndex[aSCounts[phasedIndex]>0]
pylab.scatter(phasedIndexOccupied, [yaxis_pos]*len(phasedIndexOccupied),s=40,marker='d',color='r',edgecolor='black')
except ValueError:pass
#Plot anti sense strand
if all:
aASCounts = numpy.log(self.aASCounts[self.nSize:-self.nSize])
if (nFirstPos-3)>=0:phasedIndex = numpy.arange(nFirstPos-3,len(aASCounts),self.nSize)
else: phasedIndex = numpy.arange(nFirstPos+self.nSize-3,len(aASCounts),self.nSize)
else:
aASCounts = numpy.log(self.aASCounts[self.tMinIndex[0]:self.tMinIndex[1]])
phasedIndex = numpy.arange(self.nSize-3,len(aSCounts),self.nSize)
pylab.subplot(212)
pylab.subplots_adjust(left=0.05, bottom=0.06, right=0.99, top=0.92,hspace=0.15 )
pylab.xlabel('Relative position',fontsize= 14)
pylab.ylabel('Number of small RNAs',fontsize= 14)
pylab.bar(range(len(aASCounts)),aASCounts,color='b',width=1.0,edgecolor='b')
pylab.bar(phasedIndex,aASCounts[phasedIndex],color='r',width=2,edgecolor='r',alpha=1,align='center')
yaxis_pos = max(aASCounts)/3.0*2
try:
pylab.scatter(phasedIndex, [yaxis_pos]*len(phasedIndex), marker='d', color='white',edgecolor='black')
except ValueError:pass
try:
phasedIndexOccupied = phasedIndex[aASCounts[phasedIndex]>0]
pylab.scatter(phasedIndexOccupied, [yaxis_pos]*len(phasedIndexOccupied),s=40,marker='d',color='r',edgecolor='black')
except ValueError:pass
pylab.axis([0,len(aASCounts),0,max(aASCounts)])
if display:
pylab.show()
pylab.close()
return
return fig
if __name__=='__main__':
pdf = PdfPages('test.pdf')
aSCounts = [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0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.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]
nSize = 24
loc = locus(8,225,266,24,'SL2.40ch05')
loc.aSCounts = numpy.array(aSCounts,dtype='Float64')
loc.aASCounts = numpy.array(aASCounts,dtype='Float64')
for i in xrange(2,loc.nLength-nSize+2):
for j in xrange(i+nSize,loc.nLength,loc.nSize):
if loc.aSCounts[j-nSize]==0 and loc.aASCounts[j-3]==0:continue
loc.pValue=-3.17805383035
loc.tMinIndex = (39, 63)
fig = loc.plot()
pdf.savefig(fig)
#pylab.close(fig)
pdf.close()
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users