创建pyplot图形后,为什么strftime中的工作日和月份的语言('%a%A%b%B')会发生变化?

时间:2019-02-06 17:25:20

标签: python datetime matplotlib locale

我正在运行一个脚本,该脚本首先显示datetime.now()工作日 month ,然后使用plt.figure()创建一个pyplot图形,最后再次显示datetime.now()工作日月份。创建图形后,工作日 的语言从英语更改为法语。有人知道为什么吗?谢谢。

编辑:我在代码中添加了locale.getlocale()的印刷品以获取更多信息。似乎开始时的语言环境是“ fr_FR.utf8”,但英语打印时间...

# coding: utf8

from datetime import datetime
import matplotlib.pyplot as plt
import locale

t1 = datetime.now()

print('\n', locale.getlocale())
print(t1.strftime('%a %A %b %B'))

print('\n Creating figure...')
fig = plt.figure()
plt.close(fig)

print('\n', locale.getlocale())
print(t1.strftime('%a %A %b %B'))

print("\n Setting locale to 'en_US.utf8'...")
locale.setlocale(locale.LC_ALL, 'en_US.utf8')

print('\n', locale.getlocale())
print(t1.strftime('%a %A %b %B'))

我得到的结果是:

 ('fr_FR', 'UTF-8')
Wed Wednesday Feb February

 Creating figure...

 ('fr_FR', 'UTF-8')
mer. mercredi févr. février

 Setting locale to 'en_US.utf8'...

 ('en_US', 'UTF-8')
Wed Wednesday Feb February

0 个答案:

没有答案