Python 轴上日期表达式的本地化

Python 轴上日期表达式的本地化,python,altair,Python,Altair,我尝试在altair时间序列图上显示一个时间轴,作为本地化月份。我将localed设置为适当的代码,但是十月仍然显示为oct而不是Okt import altair as alt import pandas as pd import locale from altair_saver import save file = '.\lagebericht.csv' df = pd.read_csv(file, sep=';') source = df locale.setlocale(locale

我尝试在altair时间序列图上显示一个时间轴,作为本地化月份。我将localed设置为适当的代码,但是十月仍然显示为oct而不是Okt

import altair as alt
import pandas as pd
import locale
from altair_saver import save

file = '.\lagebericht.csv'
df = pd.read_csv(file, sep=';')

source = df
locale.setlocale(locale.LC_ALL, "de_CH")

base = alt.Chart(source, title='Neumeldungen BS').encode(
    alt.X('test_datum:T', axis=alt.Axis(title="",format="%b %y"))
    )

bar = base.mark_bar(width = 1).encode(
    alt.Y('faelle_bs:Q', axis=alt.Axis(title="Anzahl Fälle"))
    )

line =  base.mark_line(color='blue').encode(
    y='faelle_Total:Q')

chart1 = (bar + line).properties(width=600)

base = alt.Chart(source, title='Meldungen kumulativ BS').encode(
    alt.X('test_datum:T', axis=alt.Axis(title="",format="%b %y"))
    )
line =  base.mark_line(color='blue').encode(
    alt.Y('faelle_bs_kum:Q', axis=alt.Axis(title="Anzahl Fälle"))
    )
            
chart2 = (line).properties(width=600)
save(chart1 & chart2, r"images\figs.html")

牵牛星连接Python和javascript;使用Python
locale
包时,它只影响Python中的语言环境。您需要做的是更改javascript显示的区域设置。可以通过渲染器
embeddeoptions
使用
formatLocale
(请参阅)和
timeFormatLocale
(请参阅)执行此操作

以下是如何使用这些链接中可用的区域设置为Altair渲染设置取消区域设置:

将altair导入为alt
从urllib导入请求
导入json
#获取并启用德语格式和时间格式区域设置。
使用request.urlopen('https://raw.githubusercontent.com/d3/d3-format/master/locale/de-DE.json“)作为f:
de_format=json.load(f)
使用request.urlopen('https://raw.githubusercontent.com/d3/d3-time-format/master/locale/de-DE.json“)作为f:
de_time_format=json.load(f)
alt.renderers.set_embed_选项(formatLocale=de_格式,timeFormatLocale=de_时间_格式)

这很有魅力,非常感谢@jakevdp。