我正在构建一个工具,用Pandas读取一个uft-8编码的文本文件,并在Matplotlib上显示该字段。可以把它想象成一个穷人的遥测显示器用于训练目的。我遇到的问题是代码没有显示西里尔语中的字段,但它能够显示txt文件中的其他字段。当该字段被硬编码时,该情节确实显示了西里尔字母'进入情节。
这是代码(你可能会看到我是这个人的新手):
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt # Plotting library
import numpy as np # Numpy library for arrays
import matplotlib.cbook as cbook
import pandas as pd
from pylab import *
import matplotlib as mpl
from pylab import rcParams
import matplotlib.cm as cm
from pandas import set_option
set_option("display.max_rows", 10) #Allows to control how Pandas displays the result
# Set image size
rcParams['figure.figsize'] = 12, 10
# Read the rndz telemetry file with pandas
filename = "data.txt"
data = pd.read_table(filename, sep="\s+")
# 361 is the size of the txt file
for i in range(361):
plt.clf() # Clears the screen
plt.xlim(0.5,8) # Set the x-limits on the display
plt.ylim(1,7) # Set the y-limits on the display
plt.text(5.9,6.70,str(data.one[i])) # Adds regular text
#This field is the one giving me trouble
plt.text(5.9,6.40,str(data.two[i]) # Add cyrillic text
#The field below is displayed properly on the plot
plt.text(1.25,6.7,u'заглавие', color="#ffffff", fontdict=font) # Add title
xticks([]), yticks([]) # Erase the axes
plt.show() # Render the plot
plt.pause(1) # Wait before the next loop executes
如果我评论data.two字段的显示,代码运行正常。但是,当要求代码绘制该字段中的文本时,这是西里尔文本,这是我得到的:
'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
我正在Windows 7中运行Enthough Canopy Python 2.7。对于什么是错误的任何想法?
答案 0 :(得分:1)
通过将void MainWindow::new()
{
...
QCompleter *cmpt;
cmpt=new QCompleter(LocationStringList,this);
cmpt->setCaseSensitivity(Qt::CaseInsensitive);
QLineEdit *locationLineEdit = new QLineEdit();
locationLineEdit->setCompleter(cmpt);
...
参数传递给encoding=
函数来回读您的utf8编码文件:
read_table