如何在Jupyter Notebook中调整ydata-profiling的热图等图表及字体大小?
调整ydata-profiling图表与字体大小的方法
ydata-profiling支持通过自定义配置参数调整图表尺寸、字体等样式,针对你提到的相关性热图、缺失值图表等场景,可通过修改ProfileReport的config参数实现需求。
1. 全局统一调整
初始化ProfileReport时传入自定义配置,批量设置图表宽高、全局字体:
import pandas as pd from ydata_profiling import ProfileReport # 自定义配置模板 custom_config = { "plot": { "dpi": 120, # 提升图表分辨率,避免模糊 "font": { "family": "Arial", "size": 12 # 全局基础字体大小 }, # 相关性热图尺寸设置 "correlation": { "heatmap": { "height": 800, "width": 800 } }, # 缺失值相关图表尺寸设置 "missing": { "bar": { "height": 600, "width": 1000 }, "heatmap": { "height": 700, "width": 700 } } } } # 应用配置生成报告 profile_test = ProfileReport( test, title="Profiling Report", interactions=None, config=custom_config ) profile_test.to_widgets()
2. 特定图表精细调优
如果需要单独调整某类图表的局部字体(比如轴标签、刻度),可细化配置参数:
custom_config = { "plot": { "correlation": { "heatmap": { "height": 900, "width": 900, "fontsize": { "x_label": 10, "y_label": 10, "title": 14, "ticks": 8 # 轴刻度字体大小 } } }, "missing": { "heatmap": { "fontsize": { "ticks": 9 } } } } }
3. 导出HTML报告的样式保留
若要将调整后的报告导出为HTML文件,直接使用to_file()方法即可,自定义配置会自动生效:
profile_test.to_file("profiling_report.html")
注意:不同版本的ydata-profiling可能存在参数细微差异,若上述配置不生效,可核对对应版本的官方文档确认参数名称。
内容的提问来源于stack exchange,提问作者user22088019
相关产品推荐
相关产品推荐

