跳到内容

定制报告

在某些情况下,用户可能希望定制报告的外观,以符合个人偏好或企业品牌。ydata-profiling 提供两个主要的定制维度:HTML 报告的样式以及其中包含的可视化和图表的样式

定制报告主题

报告的多个方面都可以定制。下表显示了可用的设置

参数 类型 默认值 描述
html.minify_html bool True 如果为 True,则使用 htmlmin 包压缩输出的 HTML。
html.use_local_assets bool True 如果为 True,所有资产(样式表、脚本、图片)都存储在本地。如果为 False,则对部分样式表和脚本使用 CDN。
html.inline boolean True 如果为 True,所有资产都包含在报告中。如果为 False,则创建一个网页导出,所有资产存储在 '[REPORT_NAME]_assets/' 目录中。
html.navbar_show boolean True 是否在报告中包含导航栏
html.style.theme string None 选择一个 bootswatch 主题。可用选项:flatly (深色) 和 united (橙色)
html.style.logo string nan 一个 base64 编码的标志,用于在导航栏中显示。
html.style.primary_color string #337ab7 报告中使用的主要颜色。
html.style.full_width boolean False 默认情况下,报告宽度是固定的。如果设置为 True,则使用屏幕的全宽。

请参阅可用的更改设置,了解如何更改和应用这些设置。

定制可视化

绘图渲染选项

将参数传递给底层 matplotlib 可视化引擎的一种方法是在计算分析时使用 plot 参数。可以使用键值对 image_format: "png" 将图片默认格式更改为 png(默认为 SVG),也可以使用 dpi: 800 更改图片的 DPI 分辨率。例如:

定制绘图渲染
1
2
3
4
5
6
profile = ProfileReport(
    planets,
    title="YData Profiling Report",
    explorative=True,
    plot={"dpi": 200, "image_format": "png"},
)

饼状图

饼状图用于绘制分类(或布尔)特征中类别的频率。默认情况下,如果一个特征的唯一值不超过 10 个,则被视为分类特征。可以使用 plot.pie.max_unique 设置配置此阈值。

控制饼状图频率
1
2
3
profile = ProfileReport(pd.DataFrame(["a", "b", "c"]))
# Changing the *max_unique* threshold to 2 will make feature non-categorical
profile.config.plot.pie.max_unique = 2

如果特征未被视为分类特征,则不会显示饼状图。因此,可以通过设置 plot.pie.max_unique = 0 来移除所有饼状图。

饼状图的颜色可以配置为任何可识别的 matplotlib 颜色,使用 plot.pie.colors 设置。

控制饼状图颜色
profile = ProfileReport(pd.DataFrame([1, 2, 3]))
profile.config.plot.pie.colors = ["gold", "b", "#FF796C"]

调色板

可视化中使用的调色板,如相关矩阵和缺失值概览,也可以通过 plot 参数进行定制。要定制相关矩阵使用的调色板,请使用 correlation

更改可视化调色板
  from ydata_profiling import ProfileReport

  profile = ProfileReport(
      df,
      title="YData Profiling Report",
      explorative=True,
      plot={"correlation": {"cmap": "RdBu_r", "bad": "#000000"}},
  )

Similarly, the palette for *Missing values* can be changed using ``missing`` argument:

``` python linenums="1" python

  from ydata_profiling import ProfileReport

  profile = ProfileReport(
      df,
      title="YData Profiling Report",
      explorative=True,
      plot={"missing": {"cmap": "RdBu_r"}},
  )

ydata-profiling 接受 matplotlib 接受的所有 cmap 值(颜色映射)。可用的颜色映射列表可以自定义调色板