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

如何在Jupyter notebook中调整ggplot2绘制图表的宽高?

解决方案

R语言 + IRkernel环境配置

在绘图代码前运行全局配置语句,自定义调整宽高数值即可,宽度参数设置越大,图表展示越宽:

options(repr.plot.width = 15, repr.plot.height = 7)

如果仅需要调整单张图表的尺寸,不需要全局生效,可以在输出ggplot对象时指定参数:

library(ggplot2)
# 你的绘图逻辑
p <- ggplot(data = df, aes(x = x, y = y)) + geom_point()

# 打印时指定尺寸
print(p, width = 16, height = 8)

Python plotnine环境配置

如果是用Python的plotnine库绘制类ggplot图表,直接在主题配置中添加尺寸设置即可:

from plotnine import *

(ggplot(df, aes(x='x', y='y'))
 + geom_point()
 + theme(figure_size=(16, 8)) # 第一个参数为宽度,第二个为高度,单位为英寸
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 13:45:00