UnicodeEncodeError当尝试使用离线可视化数据.情节的方法



程序从die类中导入die,该类表示单个6面骰子。模拟掷骰子1000次,计算每个结果的频率。当尝试使用离线可视化数据时。plotly我得到错误:

UnicodeEncodeError: 'charmap'编解码器无法在位置276398中编码字符'u25c4':字符映射到

在错误中也有下划线问题:return f.write(data)我已经研究了存储在数据变量中的信息,但将其放在offline.plot()方法中看起来是正确的。

在这个方法中也没有要传递的编码参数。下面是代码:

from plotly.graph_objs import Bar, Layout
from plotly import offline
from die import Die
# Create D6
die = Die()
results = []
for roll_num in range(1000):
result = die.roll()
results.append(result)
# Analyze the results.
frequencies = []
for value in range(1, die.num_sides + 1):
frequency = results.count(value)
frequencies.append(frequency)
# Visualize the results.
x_values = list(range(1, die.num_sides + 1))
data = [Bar(x=x_values, y=frequencies)]
x_axis_config = {'title': 'Result'}
y_axis_config = {'title': 'Frequency of Result'}
my_layout = Layout(title='Results of rolling one D6 1000 times', xaxis=x_axis_config, yaxis=y_axis_config)
offline.plot({'data': data, 'layout': my_layout}, filename='d6.html')

让我们将版本降级到5.11.0(从2022年10月27日开始)-我在练习中遇到了同样的问题。

查看PyPi.org上的发布历史历史https://pypi.org/project/plotly/

在降级后对我有效

从plotly的Github问题来看,升级到5.13.0版本应该可以解决您的问题。https://github.com/plotly/plotly.py/issues/3898

今天在使用5.12.0时遇到这个问题,同时保存HTML图,升级到5.13.0解决了这个错误。

是的,我在命令行中做了pip列表,看到我的plot版本是5.12,当我安装到5.13时它工作了。不确定崇高文本使用的文件夹是否有问题,因为我可能在命令行和崇高文本

中都安装了它

最新更新