UnicodeWarning:Unicode等同比较无法将两个参数都转换为Unicode MacOSX

时间:2014-11-07 13:44:35

标签: python unicode matplotlib osx-lion

我在Mac OS Lion上获得此错误,Python 2.7

=============================================

> /usr/local/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if rotation in ('horizontal', None):

 /usr/local/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal elif rotation == 'vertical':

============================================== < / p>

我的代码

from matplotlib import pyplot as plt    
from matplotlib import cm               # colormaps
import numpy as np

try:
    fname = 'solution.txt'

x, y, u = np.loadtxt(fname, unpack=True)
except:

err_msg = "Could not load data from file %s." % fname \
          + " Did you forget to run the program?"
raise Exception(err_msg)


# Solution is plotted on n by n grid so length of each vector should be n**2
# Determine n:

n = int(np.sqrt(len(x)))
assert n*n == len(x), "Expected len(x) to be a perfect square, len(x) = %s" % len(x)


X = x.reshape(n,n)
Y = y.reshape(n,n)
U = u.reshape(n,n)

# Pseudocolor plot

plt.figure(1)                  
plt.clf()                      # clear figure
plt.pcolor(X,Y,U,cmap=cm.jet)  # pseudo-color plot using colormap "jet"
plt.axis('scaled')             # so x- and y-axis scaled the same (square)
plt.clim(0., 1.)               # colors range from u=0 to u=1
plt.colorbar()                 # add a color bar to show temperature scale
plt.title('Temperature')

plt.savefig('pcolor.png')
print 'Saved pseudocolor plot as pcolor.png'

# Contour plot

 plt.figure(2)                  
   plt.clf()                     


# contour line levels:
clines = np.linspace(0., 1., 26)

# do contour plot:
C = plt.contour(X,Y,U,clines,colors='k') 
plt.axis('scaled')  

# add labels on every other line:
plt.clabel(C, clines[1::2], inline=1, fontsize=10)

plt.title('Contours of temperature')

plt.savefig('contour.png')
print 'Saved contour plot as contour.png'

0 个答案:

没有答案