自定义报告
在某些情况下,用户可能希望自定义报告的外观,以符合个人偏好或企业品牌。ydata-profiling 提供了两个主要的自定义维度:HTML 报告的样式和包含在其中的可视化图表的样式。
自定义报告的主题
报告的多个方面可以进行自定义。下表显示了可用的设置:
| Parameter | Type | Default | Description |
|---|---|---|---|
html.minify_html |
bool | True |
If True, the output HTML is minified using the htmlmin package. |
html.use_local_assets |
bool | True |
If True, all assets (stylesheets, scripts, images) are stored locally. If False, a CDN is used for some stylesheets and scripts. |
html.inline |
boolean | True |
If True, all assets are contained in the report. If False, then a web export is created, where all assets are stored in the '[REPORT_NAME]_assets/' directory. |
html.navbar_show |
boolean | True |
Whether to include a navigation bar in the report |
html.style.theme |
string | None |
Select a bootswatch theme. Available options: flatly (dark) and united (orange) |
html.style.logo |
string | nan | A base64 encoded logo, to display in the navigation bar. |
html.style.primary_color |
string | #337ab7 | The primary color to use in the report. |
html.style.full_width |
boolean | False |
By default, the width of the report is fixed. If set to True, the full width of the screen is used. |
请参阅可更改的设置,了解如何更改和应用这些设置。
自定义可视化
图表渲染选项
一种向底层 matplotlib 可视化引擎传递参数的方法是,在计算概要时使用 plot 参数。可以通过键值对 image_format: "png" 将图像的默认格式更改为 png(默认是 SVG),并使用 dpi: 800 更改图像的分辨率。例如:
| 自定义图表渲染 | |
|---|---|
饼图
饼图用于绘制分类(或布尔)特征中类别的频率。默认情况下,如果一个特征的唯一值不超过 10 个,则被视为分类特征。这个阈值可以通过 plot.pie.max_unique 设置进行配置。
| 控制饼图频率 | |
|---|---|
如果特征不被视为分类特征,则不会显示饼图。因此,通过设置 plot.pie.max_unique = 0 可以移除所有饼图。
饼图的颜色可以配置为任何被 matplotlib 识别的颜色,使用 plot.pie.colors 设置。
| 控制饼图颜色 | |
|---|---|
调色板
在可视化中使用的调色板,如相关矩阵和缺失值概览,也可以通过 plot 参数进行自定义。要自定义相关矩阵使用的调色板,请使用 correlation 键:
| 更改可视化调色板 | |
|---|---|
类似地,可以使用 missing 参数更改缺失值的调色板:
``` python linenums="1" python
from ydata_profiling import ProfileReport
profile = ProfileReport( df, title="Pandas Profiling Report", explorative=True, plot={"missing": {"cmap": "RdBu_r"}}, ) ```
ydata-profiling 接受 matplotlib 接受的所有 cmap 值(色图)。可用色图的列表可以在此处访问。或者,可以创建自定义调色板。
