SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Neal B. <ndb...@gm...> - 2015年07月06日 12:50:12
This code runs on python3, but on python2 I get:
Traceback (most recent call last):
 File "per_vs_lambda.py", line 35, in <module>
 ax.set_xlabel (' ')
 File "/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.py", line 
179, in set_xlabel
 return self.xaxis.set_label_text(xlabel, fontdict, **kwargs)
 File "/usr/lib64/python2.7/site-packages/matplotlib/axis.py", line 1480, 
in set_label_text
 self.label.set_text(label)
 File "/usr/lib64/python2.7/site-packages/matplotlib/text.py", line 1028, 
in set_text
 self._text = '%s' % (s,)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 0: 
ordinal not in range(128)
#!/usr/bin/python
# -*- coding: utf-8 -*-
data='''carriers,lambda,per
1,7,1.3e-4
1,8,3.0e-4
1,9,.0014
8,7,4.8e-4
8,8,1.3e-3
8,9,.0075
'''
import pandas as pd
try:
 from StringIO import StringIO
except ImportError:
 from io import StringIO
df = pd.read_csv (StringIO (data))
g = df.groupby ('carriers')
import matplotlib.pyplot as plt
import matplotlib as mpl
#mpl.rcParams['font.family'] = 'stix'
mpl.rc('font', family='DejaVu Sans')
#mpl.rc('font', family='stix')
import itertools
markers = itertools.cycle(['o','s','v']) 
fig = plt.figure() 
ax = fig.add_subplot(111)
for c, stuff in g:
 plt.semilogy (stuff['lambda'].values, stuff['per'].values, 
label='carriers=%s'%c, marker=next(markers))
plt.legend (loc='best')
ax.set_xlabel (' ') <<< this invisible character is a small greek lambda
ax.set_ylabel ('per')
plt.grid(which='major', linestyle='solid')
plt.grid(which='minor', linestyle='dashed') 
plt.savefig ('per_vs_lambda.pdf')
From: Christian A. <ia...@gm...> - 2015年07月06日 13:05:07
Have you tried making the string unicode?
ax.set_xlabel (u' ')
From: Neal B. <ndb...@gm...> - 2015年07月06日 13:15:54
Christian Alis wrote:
> Have you tried making the string unicode?
> 
> ax.set_xlabel (u' ')
> 
> 
------------------------------------------------------------------------------
Oh, thanks. That works now on py2 and py3.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /