OS: Windows 8.1 Pro
matplotlib version: 1.4.3
where obtained: http://www.lfd.uci.edu/~gohlke/pythonlibs/
customizations: none
Sample Program: attached py file; this is a Physics homework problem; I
have the answers I need, but would like to fix the errors to be able to
label all lines.
Debug output in attached output.txt file
If you uncomment line 180, the error is reported as if it came from that
line even though there is no float64 on that line (savefig). If commented,
it does not report a line from my .py file...
If you make line 170 read as follows, the error goes away:
if (maxTerm<32):
This suggests to me that the additional labels for the 32, 64, 128, and 154
term runs is what is triggering the bug, but I cannot figure out what it
is.
Also, separate note, just about any time I make figures, when closing the
last figure I get a python.exe app crash and this message:
alloc: invalid block: 00000000044E7680: 0 d
Thank you for any help,
Bobby
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
# Problem #4 - Compare e^-x to 1/e^x using Taylor-Series approximation. Use
# the error calculation to compare them.
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
# Taylor Series for e^x
#
# 2 3 4
# x x x x
# e = 1 + x + -- + -- + -- ...
# 2! 3! 4!
#
# Taylor Series for e^-x
#
# 2 3 4
# -x x x x
# e = 1 - x + -- - -- + -- ...
# 2! 3! 4!
#
# Error calculation
# 1 -x
# ------------- - system e
# x
# calculated e
# --------------------------
# -x
# system e
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
#
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
def graphMyetoNegX(maxSlices,maxTerm,myRangeStart,myRangeEnd,myFigBase):
# Initial Values
# ONE
myfpOne = np.float64(1)
myfpZero = np.float64(0)
# My "x" array, spaced lineraly from 0 to 100
myX = np.linspace(myRangeStart, myRangeEnd, maxSlices)
# I note that the numerator is an increasing power of x (from 0 to the
number
# of iterations), so I start the numerator array as all "1"s to represent
x^0
top = np.repeat(np.array([[myfpOne]]), maxSlices)
negtop = np.repeat(np.array([[myfpOne]]), maxSlices)
# I note that the denominator is simply the previous denominator multiplied
by
# the current iteration count: n! = (n-1)! * n, so start it at 0! == 1
bottom = np.repeat(np.array([[myfpOne]]), maxSlices) # 0!
# The initial e^x = the initial numerator divided by the initial denominator
etoX = top/bottom
etoNegX = negtop/bottom
# I need to have a "previous e^x" to compare and know when I have reached a
# steady-state
lastetoX = np.repeat(np.array([[myfpZero]]), maxSlices)
lastetoNegX = np.repeat(np.array([[myfpZero]]), maxSlices)
# For counting consecutive identical results
consecetoXSame = 0
consecetoNegXSame = 0
# I start at step 0 to allow the first iteration to be 1
myNumSteps = 0
# Loop until I reach maxTerm
while (myNumSteps < maxTerm):
# Keep a copy of previous e^x (had to learn that a copy was needed)
lastetoX = np.copy(etoX)
lastetoNegX = np.copy(etoNegX)
# Multiply numerator array by x array again
top *= myX
negtop *= -myX
# Increment iteration counter
myNumSteps += 1
# Multiply denominator by iteration counter (progress the n!)
bottom *= myNumSteps
# Find the new fraction to add; not strictly necessary, but helps with
# debugging
thisTerm = top/bottom
thatTerm = negtop/bottom
# Add this term to the e^x
etoX += thisTerm
etoNegX += thatTerm
# Test array equality (steady-state) and report if so
if np.array_equal(lastetoX,etoX) == True:
consecetoXSame+=1
if consecetoXSame>1:
consecstr=str(consecetoXSame)+" times."
else:
consecstr="once."
#print("No change in calculated e^x,",etoX,"vs
previous,",lastetoX,consecstr)
else:
consecetoXSame=0
if np.array_equal(lastetoNegX,etoNegX) == True:
consecetoNegXSame+=1
if consecetoNegXSame>1:
consecstr=str(consecetoNegXSame)+" times."
else:
consecstr="once."
#print("No change in calculated e^x,",etoNegX,"vs
previous,",lastetoNegX,consecstr)
else:
consecetoNegXSame=0
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
# This tells the user how many iterations it took to reach steady-state, or
# that steady-state did not occur, indicating that significant error still
# exists in the calculation
#print("After",myNumSteps,"steps, my e^-x:",etoNegX)
#print("After",myNumSteps,"steps, my 1/e^x:",myfpOne/etoX)
# Output the system calculation of e^x for comparison
#print("System e^-x:",np.exp(-myX))
r_patch = mpatches.Patch(color='red', label=r'$\frac{1}{e^x}$')
g_patch = mpatches.Patch(color='green', label=r'$e^{-x}$')
b_patch = mpatches.Patch(color='blue',label=r'system $e^{-x}$')
o_patch = mpatches.Patch(color='orange', label=r'$\frac{\frac{1}{e^x}-
system e^{-x}}{system e^{-x}}$')
k_patch = mpatches.Patch(color='black', label=r'$\frac{e^{-x}- system
e^{-x}}{system e^{-x}}$')
figStrName='PHYS404-homework1-problem3-rev05-Figure-'
figStrExt='.png'
# Plot calculated 1/e^x and the system e^-x for comparison
plt.figure(myFigBase*3+1)
plt.title(r'Calculated $\frac{1}{e^x}$ vs System $e^{-x}$,
'+'\n'+str(myRangeStart)+' <= x <= '+
str(myRangeEnd)+' in '+str(maxSlices)+' slices, taken to
'+str(maxTerm)+' Taylor terms')
plt.grid(True)
plt.xlabel('x')
plt.ylabel(r'$e^{-x}$')
plt.text(myX[maxSlices-2500],myfpOne/etoX[maxSlices-2500],str(maxTerm),rotation=0,color='red')
plt.legend(handles=[r_patch,b_patch],loc=2)
plt.loglog(myX,myfpOne/etoX,'red')
plt.loglog(myX,np.exp(-myX),'blue',ls='--')
plt.savefig(figStrName+str(myFigBase*3+1).zfill(2)+figStrExt,bbox_inches='tight')
# Plot calculated e^-x and the system e^-x for comparison
plt.figure(myFigBase*3+2)
plt.title(r'Calculated $e^{-x}$ vs System $e^{-x}$,
'+'\n'+str(myRangeStart)+' <= x <= '+
str(myRangeEnd)+' in '+str(maxSlices)+' slices, taken to
'+str(maxTerm)+' Taylor terms')
plt.grid(True)
plt.xlabel('x')
plt.ylabel(r'$e^{-x}$')
plt.text(myX[maxSlices-2500],etoNegX[maxSlices-2500],str(maxTerm),rotation=0,color='green')
plt.legend(handles=[g_patch,b_patch],loc=2)
plt.loglog(myX,etoNegX,'green')
plt.loglog(myX,np.exp(-myX),'blue',ls='--')
plt.savefig(figStrName+str(myFigBase*3+2).zfill(2)+figStrExt,bbox_inches='tight')
# Plot error between calculated values and system values
plt.figure(myFigBase*3+3)
plt.title(r'Calculated Error for $\frac{1}{e^x}$ & $e^{-x}$ vs System
$e^{-x}$, '+'\n'+
str(myRangeStart)+' <= x <= '+str(myRangeEnd)+' in
'+str(maxSlices)+
' slices, taken to '+str(maxTerm)+' Taylor terms')
plt.grid(True)
plt.xlabel('x')
plt.ylabel(r'Calculated Error via $\frac{observed-actual}{actual}$')
myOneOveretoX=(myfpOne/etoX-np.exp(-myX))/np.exp(-myX)
myetoNegX=(etoNegX-np.exp(-myX))/np.exp(-myX)
if (maxTerm<32) or ((myFigBase<4) and (maxTerm<64)):
myInd=60*maxTerm
myPltTxtX=myX[myInd]
myPltTxtY1=myOneOveretoX[myInd]
plt.text(myPltTxtX,myPltTxtY1,str(maxTerm),rotation=0,color='orange')
myPltTxtY2=myetoNegX[myInd]
plt.text(myPltTxtX,myPltTxtY2,str(maxTerm),rotation=0,color='black')
plt.legend(handles=[o_patch,k_patch],loc=2)
plt.loglog(myX,myOneOveretoX,'orange')
plt.loglog(myX,myetoNegX,'black')
#
plt.savefig(figStrName+str(myFigBase*3+3).zfill(2)+figStrExt,bbox_inches='tight')
# Number of slices (array size) to calculate
mySlices = 10000
plt.close('all')
# ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+-
# Number of Taylor Series terms; system overflow appaears to happen around
# 154; i.e., x^155 when x -> 100 returns an overflow
myTaylorRuns = [2,4,8,16,32,64,128,154]
for myRuns in myTaylorRuns:
graphMyetoNegX(mySlices,myRuns,0,1,0)
graphMyetoNegX(mySlices,myRuns,1,10,1)
graphMyetoNegX(mySlices,myRuns,10,100,2)
graphMyetoNegX(mySlices,myRuns,0,100,3)
plt.show()
#plt.close('all')
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Python34\lib\site-packages\matplotlib\backends\backend_tkagg.py",
line 278, in resize
self.show()
File "C:\Python34\lib\site-packages\matplotlib\backends\backend_tkagg.py",
line 349, in draw
FigureCanvasAgg.draw(self)
File "C:\Python34\lib\site-packages\matplotlib\backends\backend_agg.py", line
469, in draw
self.figure.draw(self.renderer)
File "C:\Python34\lib\site-packages\matplotlib\artist.py", line 59, in
draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python34\lib\site-packages\matplotlib\figure.py", line 1085, in draw
func(*args)
File "C:\Python34\lib\site-packages\matplotlib\artist.py", line 59, in
draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python34\lib\site-packages\matplotlib\axes\_base.py", line 2110, in
draw
a.draw(renderer)
File "C:\Python34\lib\site-packages\matplotlib\artist.py", line 59, in
draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Python34\lib\site-packages\matplotlib\text.py", line 642, in draw
ismath=ismath, mtext=mtext)
File "C:\Python34\lib\site-packages\matplotlib\backends\backend_agg.py", line
206, in draw_text
font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc)
File "C:\Python34\lib\site-packages\numpy\core\fromnumeric.py", line 2648, in
round_
return round(decimals, out)
File "C:\Python34\lib\site-packages\numpy\ma\core.py", line 4903, in round
result._mask = self._mask
AttributeError: 'numpy.float64' object has no attribute '_mask'
$HOME=C:\Users\Bobby
matplotlib data path C:\Python34\lib\site-packages\matplotlib\mpl-data
*****************************************************************
You have the following UNSUPPORTED LaTeX preamble customizations:
Please do not ask for support with these customizations active.
*****************************************************************
loaded rc file C:\Python34\lib\site-packages\matplotlib\mpl-data\matplotlibrc
matplotlib version 1.4.3
verbose.level debug
interactive is False
platform is win32
loaded modules: <dict_keyiterator object at 0x0000000003B9AE08>
CACHEDIR=C:\Users\Bobby\.matplotlib
Using fontManager instance from C:\Users\Bobby\.matplotlib\fontList.py3k.cache
backend TkAgg version 8.6
findfont: Matching
:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium
to Bitstream Vera Sans
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf')
with score of 0.000000
findfont: Matching
:family=STIXNonUnicode:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXNonUnicode
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUni.ttf')
with score of 0.000000
findfont: Matching
:family=STIXGeneral:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXGeneral
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneral.ttf')
with score of 0.000000
findfont: Matching
:family=STIXSizeThreeSym:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXSizeThreeSym
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXSizThreeSymReg.ttf')
with score of 0.000000
findfont: Matching
:family=STIXSizeFourSym:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXSizeFourSym
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXSizFourSymReg.ttf')
with score of 0.000000
findfont: Matching
:family=STIXSizeFiveSym:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXSizeFiveSym
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXSizFiveSymReg.ttf')
with score of 0.000000
findfont: Matching
:family=STIXSizeOneSym:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXSizeOneSym
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXSizOneSymReg.ttf')
with score of 0.000000
findfont: Matching
:family=STIXSizeTwoSym:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXSizeTwoSym
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXSizTwoSymReg.ttf')
with score of 0.000000
findfont: Matching
:family=STIXNonUnicode:style=normal:variant=normal:weight=bold:stretch=normal:size=12.0
to STIXNonUnicode
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniBol.ttf')
with score of 0.000000
findfont: Matching
:family=STIXGeneral:style=normal:variant=normal:weight=bold:stretch=normal:size=12.0
to STIXGeneral
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralBol.ttf')
with score of 0.000000
findfont: Matching
:family=STIXGeneral:style=italic:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXGeneral
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXGeneralItalic.ttf')
with score of 0.000000
findfont: Matching
:family=STIXNonUnicode:style=italic:variant=normal:weight=normal:stretch=normal:size=12.0
to STIXNonUnicode
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\STIXNonUniIta.ttf')
with score of 0.000000
findfont: Matching
:family=cmss10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmss10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmss10.ttf')
with score of 0.000000
findfont: Matching
:family=cmr10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmr10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmr10.ttf')
with score of 0.000000
findfont: Matching
:family=cmex10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmex10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmex10.ttf')
with score of 0.000000
findfont: Matching
:family=cmtt10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmtt10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmtt10.ttf')
with score of 0.000000
findfont: Matching
:family=cmmi10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmmi10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmmi10.ttf')
with score of 0.000000
findfont: Matching
:family=cmb10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmb10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmb10.ttf')
with score of 0.000000
findfont: Matching
:family=cmsy10:style=normal:variant=normal:weight=normal:stretch=normal:size=12.0
to cmsy10
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\cmsy10.ttf')
with score of 0.000000
findfont: Matching
:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=large
to Bitstream Vera Sans
('c:\\python34\\lib\\site-packages\\matplotlib\\mpl-data\\fonts\\ttf\\Vera.ttf')
with score of 0.000000
Could not load matplotlib icon: can't use "pyimage10" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage19" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage28" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage37" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage46" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage55" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage64" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage73" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage82" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage91" as iconphoto: not a photo
image
Could not load matplotlib icon: can't use "pyimage100" as iconphoto: not a
photo image
------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users