10 · Unicode labels and a custom theme
Chinese, English, Greek, mathematical symbols, custom fills, guide colors, an explicitly enabled full table border, and font fallback behavior are exercised together. Other gallery cases use the default three-rule table with no internal row separators or vertical column separators. Column-header height automatically adjusts to keep the labels inside their boundaries.
Run the example
from forestploter import read_forest_data
from forestploter.gallery_cases import plot_unicode_custom_theme
df = read_forest_data("10_unicode_custom_theme.xlsx", sheet_name="Forest")
result = plot_unicode_custom_theme(df)
result.save("10_unicode_custom_theme.png", dpi=300)
Plot function used by the gallery and tests
def plot_unicode_custom_theme(df: ForestInput) -> ForestPlotResult:
"""Plot case 10: Unicode labels and a custom theme."""
columns = (
ForestColumn("结局", "结局 / Outcome", "text", 2.2),
ForestColumn("人群", "研究人群 / Population", "text", 2.2),
ForestColumn("样本量", "样本量 N", "numeric", 0.7, "right"),
ForestColumn("效应值", "效应值 [95% CI]", "numeric", 1.8, "right"),
ForestColumn("ci", "治疗效应 / Treatment effect", "ci", 3.3, "center"),
)
custom_theme = ForestTheme(
base_font_size=8.8,
header_fill="#F3E8FF",
alternate_fill="#FAF7FC",
group_fill="#EDE9FE",
ci_colors=("#6B3FA0",),
summary_fill="#6B3FA0",
reference_color="#374151",
ideal_color="#C47F17",
show_table_border=True,
show_vertical_grid=True,
)
return forest(
df,
columns=columns,
ref_line=0.0,
ideal_line=-0.2,
xlim=(-1.0, 1.0),
ticks_at=(-1.0, -0.5, 0.0, 0.5, 1.0),
arrow_lab=("治疗 / Treatment", "对照 / Control"),
title="多语言标签与自定义主题 / Multilingual labels and custom theme",
figure_width=13.0,
row_height=0.40,
theme=custom_theme,
reference_legend=ForestReferenceLegendSpec(
reference_label="无差异 / No difference",
ideal_label="目标效应 / Target",
location="bottom",
column_key="ci",
ncol=2,
),
table_layout=ForestTableLayoutSpec(max_figure_width=16.0),
)