You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Matplotlib保存SVG时绘图超画布边界问题及矢量图格式疑问

SVG保存时绘图超出画布边界问题

我将图像保存为.svg文件时,绘图超出了画布边界,但保存为png文件时无此问题。原本以为ax.set_xlim(xmin,xmax)会作为绘图的边界,无论保存为何种文件类型。

相关代码如下:

%matplotlib qt
fig, ax = plt.subplots(constrained_layout=True)
xmin,xmax= 350,800
# ############################################################################################################
x = np.arange(200,900,1)
y = np.random.rand(len(x))
ax.plot(x,y,label="noise")
#############################################################################################################
leg = ax.legend(loc="upper right")
ax.set_ylim(-0.02,2)
ax.set_xlim(xmin,xmax)
plt.show()

补充说明:

  • 我使用SVG是因为需要矢量图用于LibreOffice Impress;
  • 也想用于PowerPoint,但似乎它不支持矢量图?或许我应该改用其他文件类型?

内容的提问来源于stack exchange,提问作者Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:04:55