用途:该技能用于使用 Python 的 matplotlib 库创建静态、动画和交互式图表,覆盖 pyplot(MATLAB 风格)与面向对象 Figure/Axes 两种接口,并给出出版级可视化实践建议。
主要能力:支持折线、散点、柱状、直方图、热图、等高线、箱线、小提琴及 3D 图;支持多面板布局(subplots、subplot_mosaic、GridSpec);可定制颜色、样式表、rcParams、文本与注释;可导出 PNG/PDF/SVG,并控制 dpi、bbox_inches、透明背景等参数。
使用方式:推荐面向对象接口,如 fig, ax = plt.subplots(figsize=(10, 6)),再调用 ax.plot 等;保存用 plt.savefig('plot.png', dpi=300, bbox_inches='tight')。技能附带可运行脚本:python scripts/plot_template.py --plot-type all --output figure.png 渲染多种图型;python scripts/style_configurator.py --preset publication --output my_style.mplstyle 导出样式表。脚本需 matplotlib>=3.9 与 numpy,直方图示例还需 scipy。
适用场景:科学统计可视化、多子图排版、Jupyter 或 GUI 集成、3D 绘图等。若需从 DataFrame 快速统计图、交互式 HTML 图表、期刊级配色或流程图,资料建议改用其他对应技能。
限制与注意:避免重叠元素可用 constrained_layout=True 或 tight_layout();注意 figsize 单位为英寸;3.11 起移除 matplotlib.cm.get_cmap、plot_date 与 boxplot 的 labels=,改用 matplotlib.colormaps[name]、plot 传 datetime、tick_labels=;vert= 等已弃用。官方文档见 https://matplotlib.org/。