python - 尝试绘制数组时出现 Unicode 错误?
问题描述
我有一个非常简单的代码,并试图将生成的 numpy 数组绘制pos
为 的函数t
,但我得到一个随机的 unicode 错误。我以前从未出现过这个错误,我不知道它的含义或它为什么会出现在这段代码中:
import numpy as np
import matplotlib.pyplot as plt
h = 0.5
x_0 = 1
w = 1
t = np.arange(0, 20, h)
pos, v = np.zeros(len(t)), np.zeros(len(t))
pos[0], v[0] = x_0, 0
def a(pos):
return -w**2 * pos
for i in range(1, len(t)):
# Stormer-Verlet method
pos[i] = pos[i-1] + h*(v[i-1] + 0.5*h*a(pos[i-1]))
v[i] = v[i-1] + 0.5*h*a(pos[i-1]) + 0.5*h*a(pos[i])
# Plotting position as a function of time
plt.plot(t, pos, label='Störmer-Verlet approximation')
在线plt.plot
时,我收到此错误:UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)
. 我还打印pos
并确认它是一个预期的数组,长度为 100(与 相同的长度t
)。有谁知道为什么会这样?
解决方案
推荐阅读
- java - PDF 下载或意图
- apache-kafka - Prometheus 的 Kafka 性能指标
- c - 为什么 fprintf() 不写入文件?
- javascript - 将Vue添加到现有的旧网站,删除div而不是显示旧的html
- nativescript-vue - 有没有办法在 .vue 文件的模板部分使用 pug 编译器
- node.js - sh: 1: cross-env: laravel mix 的权限被拒绝
- python - 在 to_sql 之后打开空闲 Postgres 连接的熊猫?
- jquery - 我的 ajax 脚本中返回 NoneType 到 views.py 的错误在哪里
- javascript - 我怎样才能做一个JavaScript代码结合自动滑块和手动滑块?
- python - 按 Pandas GroupBy 中的列表列分组