论文写作:PyPlot或MATLAB图像全局客制化与矢量图导出
Python
在PyPlot中,我们可以进行这样的设置,对matplotlib进行客制化,并导出矢量图:
# 在使用pyplot绘图,可以通过下面的参数进行全局的客制化 from matplotlib import pyplot as plt plt.rcParams['axes.grid'] = True plt.rcParams['figure.dpi'] = 600 plt.rcParams['figure.figsize'] = (8, 4) plt.rcParams['font.family'] ='serif' plt.rcParams['lines.linewidth'] = 1 plt.rcParams['mathtext.fontset'] = 'cm' plt.rcParams['savefig.format'] = 'pdf' plt.rcParams['savefig.transparent'] = True plt.rcParams['savefig.bbox'] = 'tight' plt.rcParams['savefig.pad_inches'] = 0 plt.rcParams['pdf.fonttype'] = 42 plt.rcParams['ps.fonttype'] = 42 # 如果在Juypter Notebook里,也可以通过下面的方式显示矢量图 import matplotlib_inline matplotlib_inline.backend_inline.set_matplotlib_formats('svg') # 在导出图片时,记得选择矢量图格式(如PDF、SVG、EPS),例如: plt.savefig('test.pdf')
Matplotlib默认使用Type 3字体,这在许多期刊和会议是不被允许的。参考《Avoiding Type 3 fonts in matplotlib plots》,我们fonttype其设置为42,指定导出的PDF使用True Type字体。
更多参数可以参阅官方文档:Customizing Matplotlib with style sheets and rcParams
MATLAB
在MATLAB中,我们可以进行这样的设置,对MATLAB进行客制化,并导出矢量图:
% MATLAB图像全局客制化 % 字体使用CMU Serif字体,与LaTeX保持一致 set(0, 'DefaultTextFontname', 'CMU Serif'); set(0, 'DefaultAxesFontName', 'CMU Serif'); % 默认打开MATLAB的网格线 set(groot, 'defaultAxesXGrid', 'on'); set(groot, 'defaultAxesYGrid', 'on'); set(groot, 'defaultAxesZGrid', 'on'); % 去除导出图片的白色边缘 set(groot, 'defaultAxesXLimSpec', 'padded'); set(groot, 'defaultAxesYLimSpec', 'padded'); set(groot, 'defaultAxesZLimSpec', 'padded');
我们可以通过这样的命令导出图片
figure(); % ... 绘图命令 ... % pbaspect([3 1 1]) % 设置各个坐标轴的比例 exportgraphics(gcf, 'img.pdf') % 导出矢量图格式的图片,如PDF、SVG、EPS等
本文版权,除注明引用的部分外,归作者所有。本文严禁商业用途的转载。非商业用途的转载需在网页明显处署上作者名称及原文链接。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)